IP address of webserver

J

Johny

How can I find server's IP address?
From console I can use ping, for example:

C:\RobotP\cgi-bin>ping www.google.com

Pinging www.google.com [209.85.129.147] with 32 bytes of data:

Reply from 209.85.129.147: bytes=32 time=30ms TTL=244
Reply from 209.85.129.147: bytes=32 time=30ms TTL=244
...
...
So I know that www.google.com has 209.85.129.147 IP address.
But how can I find it directly from Python script?
Thanks for help
J.
 
G

Gabriel Genellina

How can I find server's IP address?
From console I can use ping, for example:

C:\RobotP\cgi-bin>ping www.google.com
Pinging www.google.com [209.85.129.147] with 32 bytes of data:
[...]
But how can I find it directly from Python script?

py> import socket
py> help(socket.gethostbyname)
Help on built-in function gethostbyname in module _socket:

gethostbyname(...)
gethostbyname(host) -> address

Return the IP address (a string of the form '255.255.255.255') for a
host.

py> socket.gethostbyname("www.google.com")
'209.85.165.147'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top