summaryrefslogtreecommitdiff
path: root/project2/proj2_s4498062/dns_client.py
blob: 0f5e50f3b36c25ac7d597ece7c55eda06ff2af37 (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
29
30
31
32
33
34
35
#!/usr/bin/env python2

""" Simple DNS client

A simple example of a client using the DNS resolver.
"""

import dns.resolver


def main():
    """DNS 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(args.caching, args.ttl)
    hostname, aliases, addresses = resolver.gethostbyname(args.hostname)

    # Print output
    print hostname
    print aliases
    print addresses

if __name__ == "__main__":
    main()