From 7120add95d0c5b8a97af861785ec9fe1cfc7eaee Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 2 May 2016 15:36:05 +0200 Subject: dos2unix --- project2/proj2_s4498062/dns_client.py | 62 +++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'project2/proj2_s4498062/dns_client.py') 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() + -- cgit v1.2.3