The sockets module provides an easy way to look up a host name’s ip address.

import socket

addr1 = socket.gethostbyname('google.com')
addr2 = socket.gethostbyname('yahoo.com')

print(addr1, addr2)

Which will output the following ip addresses:

173.194.121.9 98.138.253.109

 

Leave a Reply

Your email address will not be published. Required fields are marked *