ip address?

Jason Orendorff jason at jorendorff.com
Sat Jan 26 17:47:33 CET 2002


Emile van Sebille writes:
> >>> import os
> >>> ipaddr = [ i for i in os.popen('route print').readlines()
>   if i.split()[0] == '0.0.0.0' ][0].split()[3]

...where ordinary humans would write something awful like...

import os

def get_address():
    f = os.popen('route print', 'r')
    lines = f.readlines()
    f.close()

    for line in lines:
        fields = line.split()
        if fields[0] == '0.0.0.0':
            return fields[3]
    raise Exception, 'no routes found'

## Jason Orendorff    http://www.jorendorff.com/







More information about the Python-list mailing list