[Tutor] Detecting my own IP address?
bill at celestial.net
Sun Jun 5 20:29:23 CEST 2005
On Sun, Jun 05, 2005, Lee Harr wrote:
>>At present, the only thing I can think of is to redirect the
>>output of 'ifconfig' into a temporary file, then read it back in and use
>>Python and regular expressions to try and extract the IP info from that.
Why go to a temporary file when you can open a pipe?
fh = os.popen('ifconfig') #...
The advantage of parsing ifconfig output instead of using socket calls is
that it allows you to discriminate between multiple interfaces (e.g. most
of our dual hosted machines have the primary interface on the private
address which probably isn't what is required).
One disadvantage of parsing ifconfig is that output varies depending on the
INTERNET: bill at Celestial.COM Bill Campbell; Celestial Systems, Inc.
UUCP: camco!bill PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
``The fact is that the Constitution was intended to protect us from
the government, and we cannot expect the government to enforce it
willingly'' -- Dave E. Hoffmann, Reason Magazine March 2002
More information about the Tutor