How to do it...

Now we will use dnspython to find the same details of a web URL that we earlier found using dig and host commands.

Listing 11.3 gives a simple, yet verbose code to offer the details of resource records of a given URL:

#!/usr/bin/env python 
# Python Network Programming Cookbook, Second Edition   -- Chapter - 11 
# This program is optimized for Python 2.7.12 and  Python 3.5.2. 
# It may run on any other version with/without modifications. import argparse import dns.zone import dns.resolver import socket def main(address): # IPv4 DNS Records answer = dns.resolver.query(address, 'A') for i in xrange(0, len(answer)): print("Default: ", answer[i]) # IPv6 DNS Records try: answer6 = dns.resolver.query(address, 'AAAA') for i in xrange(0, ...

Get Python Network Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.