summaryrefslogtreecommitdiff
path: root/project2/proj2_s4498062/dns_client.py
blob: ab92f31da6acc692bf1b6222b442fdfcf4507f8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)