[Tutor] Detecting my own IP address?

Bill Campbell bill at celestial.net
Mon Jun 6 06:27:56 CEST 2005


On Mon, Jun 06, 2005, Simon Gerber wrote:
>Thank you for your suggestions everyone.
>
>I do wish to parse ifconfig, as I'm specifically after the address of
>ppp0. At this stage, I'm only writing the script for my own machine,
>so the downside to parsing ifconfig does not yet apply. I'm a little
>curious, however. When you say 'varies depending on the operarating
>system', are you talking about Windows vs. Linux, or, say, Debian vs.
>Gentoo?

The output format of ifconfig varies slightly on several Linux machines we
have running here ranging from SuSE 9.3 Professional as far back as Caldera
OpenLinux 1.2 or so.  It's different on the FreeBSD box I'm using for e-
mail now, and on an OS X box.  SCO OpenServer doesn't return anything
useful from ifconfig with now arguments, and one has to parse the output of
``netstat -in'' to get the interface names, then run ifconfig on each name
to get full info.

The differences aren't great, and it's easy to write regular expressions to
extract things like IP address (ipv4 and ipv6), netmask, MAC address, etc.
One could probably build a dictionary of regular expressions, keyed on the
first and third entries in os.uname() output.

I don't do Windows so can't say what it does (knowing Microsoft, it may
vary between Windows versions, patch levels, and the phase of the moon :-).

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

``... because most politicians and bureaucrats are technological idiots,
it's going to be crucial for the rank and file members of the IT community
to find its collective voice soon.'' --Michael Vizard, InfoWorld Editor in
Chief.


More information about the Tutor mailing list