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.


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

import socket
hostnames=open('host.txt').readline()
for host in hostnames:
    print host.strip(),socket.gethostbyname(host.strip())
output:
www.google.com 216.58.203.228
www.youtube.com 74.125.200.190
www.vicz.in 104.18.46.75
blog.vicz.in 104.18.46.75
Screenshot:

 

 

Here you can find out more network scripts using python https://github.com/vishnu-ks/Python-networking-scripts



Comments

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

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

    ReplyDelete

Post a Comment

Popular Posts