[python]Resolving a group of fqdns and store the ip addresses

Looking at the reference above is much easier than reading the actual socket documentation. My purpose is to find a python way to resolve a group of hostnames and return them as ip addresses.

Here’s the same code.

import logging,socket

hostnames = []
answers = []

hostnames = input("Enter hostnames with comma: ").split(",")
for hostname in hostnames:
        answer = socket.gethostbyname(hostname)
        logging.info("Getting resolution answers from DNS for hostname {}".format(hostname))
    except Exception as e:

for i in answers:
    logging.info("Listing ip addresses...")

Here’s a test:

Enter hostnames with comma: www.google.com,www.hotmail.com,pool.ntp.org,cyruslab.net

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s