how to get my internet ip address?
gh_pythonlist at gmx.de
Sat Jan 26 07:40:10 CET 2002
Le 26/01/02 à 02:19, Van Gale écrivit:
> "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.
Alas, it's not that simple :-( My FreeBSD gateway at home has two
ethernet cards, and you'd have to check the default route to know which
one is connected to the DSL router. And even then, the DSL router
doesn't have a publicly routed IP address, but only an internal one in
my ISP's network.
If I understand correctly, you'd like to parse the output of the
ipconfig.exe commandline tool. That's easily possible with the popen
function in the os module.
This sig powered by Python!
Außentemperatur in München: 7.3 °C Wind: 4.8 m/s
More information about the Python-list