diff options
author | Camil Staps | 2016-05-02 15:36:05 +0200 |
---|---|---|
committer | Camil Staps | 2016-05-02 15:36:05 +0200 |
commit | 7120add95d0c5b8a97af861785ec9fe1cfc7eaee (patch) | |
tree | 986d3801536e5d45937ee3d22474bc6eca120819 /project2/proj2_s4498062/dns_client.py | |
parent | Assignment 5 (diff) |
dos2unix
Diffstat (limited to 'project2/proj2_s4498062/dns_client.py')
-rw-r--r-- | project2/proj2_s4498062/dns_client.py | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/project2/proj2_s4498062/dns_client.py b/project2/proj2_s4498062/dns_client.py index ab92f31..d89c1e4 100644 --- a/project2/proj2_s4498062/dns_client.py +++ b/project2/proj2_s4498062/dns_client.py @@ -1,28 +1,34 @@ -#!/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)
+#!/usr/bin/env python2 +""" Simple DNS client + +A simple example of a client using the DNS resolver. +""" + +import dns.resolver + +def main(): + """Run the client""" + # 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 + +if __name__ == "__main__": + main() + |