ip address?

Emile van Sebille emile at fenx.com
Fri Jan 25 19:33:26 EST 2002


"maximilianscherr" <MaximilianScherr at T-Online.de> wrote in message
news:mailman.1012002740.18212.python-list at python.org...
> how can i get the internet ip address of my connected pc?
>
>

There are probably better ways to do it, but I know I can find it in the
output from ipconfig on windows and ifconfig on linux, so I tend to go
straight for that and parse what I need.  This seems to work on both for
single IP address systems:

import os,sys

cmd = {'win32':'ipconfig','linux2':'ifconfig'}[sys.platform]

ipaddr = [ i.split(":")[1]
    for i in os.popen(cmd).readlines()
    if i.upper().find(' ADDR')>-1 ][0].split()[0]

HTH,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list