Publish Forum topic Publish your post to the cyberwarzone forum for free and no registration!

How to get IP from hostname in Python + code

If you want to get the IP from a hostname in Python, you can use the socket module which is already included in Python. The next thing which you will need, is a variable that will hold the hostname which you want to request.

The second variable is the address variable. The IPHOLDER variable will hold the IP which you received by using socket.gethostbyname(hostname)

The print line will print out the found IP address.

get IP from hostname in Python

import socket
hostname = 'cyberwarzone.com'
IPHOLDER = socket.gethostbyname(hostname)
print '[ADDRESS] ', hostname, ' - ', IPHOLDER

Please spread the word :)

  • RSS
  • Follow by Email
  • Facebook
  • Google+
    http://cyberwarzone.com/get-ip-hostname-python-code/">