O'Reilly logo

Python Network Programming Cookbook - Second Edition by Dr. M. O. Faruque Sarker, Pradeeban Kathiravelu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required