On 2005-04-15, codecraig <[EMAIL PROTECTED]> wrote: > hi, > how can i use python to figure the ip address of the machine which > the python script is running on? I dont mean like 127.0.0.1....but i > want the external IP address (such as ipconfig on windows displays). > > any ideas?? >
I use this: #conf.py ifconfig = '/sbin/ifconfig' iface = 'eth0' telltale = 'inet addr:' #addr.py import commands from conf import ifconfig, iface, telltale def my_addr(): cmd = '%s %s' % (ifconfig, iface) output = commands.getoutput(cmd) inet = output.find(telltale) if inet >= 0: start = inet + len(telltale) end = output.find(' ', start) addr = output[start:end] else: addr = '' -- http://mail.python.org/mailman/listinfo/python-list