Ping a website address to return an IP
Hey, i'm new to python programing and i have problem that i can't decifer the answer to though a googl开发者_JAVA技巧e search.
I need to ping a website address (eg www.google.com) and have python return me a IP address.
Cheers
you want to do a "DNS lookup" :
import socket
print socket.gethostbyname('www.google.com')
Output:
74.125.230.112
EDIT:
For IPv6 support, you can use getaddrinfo(). However, I'm not sure that is what you want ;)
You want to do an NS lookup?
>>> import socket
>>> print socket.getaddrinfo('www.google.com', 80)
@Jarred, gethostbyname() as stated in the documentation, does not support IPv6. Also if you look at the result of getaddrinfo()
, there are other ip addresses related to "www.google.com".
精彩评论