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
Recommended Python Training
Course: Python 3 For Beginners
Over 15 hours of video content with guided instruction for beginners. Learn how to create real world applications and master the basics.