how to get my internet ip address?

Van Gale cgale1 at _remove_home.com
Fri Jan 25 21:19:40 EST 2002


"maximilianscherr" <MaximilianScherr at T-Online.de> wrote...
> how cna i get my actual ip address in the internet?
> using win32 so, if i could read out the information of ipconfig, i
> would be happy enough. but how do i get the output?

>From a 30 second glance at the Python documentation at
http://python.org/doc/2.2/lib/module-socket.html I see this:

    If you want to know the current machine's IP address, you may want to
use gethostbyname(gethostname()). This operation assumes that there is a
valid address-to-host mapping for the host, and the assumption does not
always hold.

So this will work assuming your Windows TCP is properly configured:

import socket
ip = socket.gethostbyname(socket.gethostname())

Sometimes the documentation gives quicker answers than Usenet :)

Van






More information about the Python-list mailing list