diff options
Diffstat (limited to 'project2/proj2_s4498062/dns_client.py')
-rw-r--r-- | project2/proj2_s4498062/dns_client.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/project2/proj2_s4498062/dns_client.py b/project2/proj2_s4498062/dns_client.py new file mode 100644 index 0000000..ab92f31 --- /dev/null +++ b/project2/proj2_s4498062/dns_client.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python2
+
+""" Simple DNS client
+
+A simple example of a client using the DNS resolver.
+"""
+
+import dns.resolver
+
+if __name__ == "__main__":
+ # Parse arguments
+ import argparse
+ parser = argparse.ArgumentParser(description="DNS Client")
+ parser.add_argument("hostname", help="hostname to resolve")
+ parser.add_argument("-c", "--caching", action="store_true",
+ help="Enable caching")
+ parser.add_argument("-t", "--ttl", metavar="time", type=int, default=0,
+ help="TTL value of cached entries")
+ args = parser.parse_args()
+
+ # Resolve hostname
+ resolver = dns.resolver.Resolver(["localhost"], 15, args.caching, args.ttl)
+ hostname, aliases, addresses = resolver.gethostbyname(args.hostname)
+
+ # Print output
+ print(hostname)
+ print(aliases)
+ print(addresses)
|