How to find out IP addresses for a list of hostnames?

Python for network scripting

As you all know python is a generic language, it can be used in networking field as well. May the below python script will be great time saver for network ninjas😎.

Here we are using a python package called socket. This package is used for socket programming. The given script will read a set of host names line by line from a file to a list. Then it will resolve all the host names and will display the IP address of the corresponding host name.

First we will create a text file host.txt with some host names to resolve. Here I will be using some domain names like,,, You can also use the same as an example. These domain names you should write line by line in the host.txt.

import socket
for host in hostnames:
    print host.strip(),socket.gethostbyname(host.strip())



Here you can find out more network scripts using python


  1. I read your post and got it quite provides great knowledge about the IP address.If anyone looking for best vpn service than visit here vpn dedicated ip

  2. Truly nice information shared by you to know about in this matter. You can find more details on buy dedicated vpn after visiting


Post a Comment

Popular Posts