portable Python ifconfig



Hi all,

I'm looking for a portable (FreeBSD and Linux) way of getting typical
ifconfig information into Python.

Some research on the web brought me to Linux only solutions

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439094
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439093

which I didn't manage to port to FreeBSD (I'm not that experienced).
Finally though, I found out about pyifconfig:

http://mail.python.org/pipermail/python-list/1999-August/009274.html

which compiles fine on Linux after changing <python1.5/Python.h> to
<python2.4/Python.h>. On FreeBSD there is no SIOCGIFHWADDR, so I
just commented out that part.

I can now do

In [1]: from pyifconfig import pyifconfig

In [2]: pyifconfig('ath0')
Out[2]:
{'addr': '192.168.50.104',
'brdaddr': '192.168.50.255',
'hwaddr': '00:17:f2:4c:a5:0c',
'netmask': '255.255.255.0'}

on Linux, and

In [1]: from pyifconfig import pyifconfig

In [2]: pyifconfig('vr1')
Out[2]:
{'addr': '192.168.50.1',
'brdaddr': '192.168.50.255',
'hwaddr': '\xff\xff',
'netmask': '255.255.255.0'}

on FreeBSD.

The problem now is that I get seemingly random information when I pass a
non-existing interface, a down interface or an empty string to
pyifconfig, which is very hard to figure out from inside a script:

In [3]: pyifconfig('foobar')
Out[3]:
{'addr': '104.154.165.183',
'brdaddr': '104.154.165.183',
'hwaddr': '00:00:68:9a:a5:b7',
'netmask': '104.154.165.183'}

so, any pointers here on how I can go on from this point?

any help is appreciated

--
regards,
BBBart

Wormwood : Calvin, how about you?
Calvin : Hard to say ma'am. I think my cerebellum just fused.
.



Relevant Pages

  • Re: FreeBSD 4.x Opteron Question
    ... the FreeBSD developers told everyone that 5.3 was da ... initially over linux not because there's a bunch of good guys on the ... My tests measure kernel performance; ... > a networking device is a key performance indicator. ...
    (freebsd-questions)
  • Re: Newbie Experience
    ... I've only been around since FreeBSD 5.4 ... FreeBSD kernel too. ... always sunshine and linux is farts. ... in the hey day of AT&T Unix I'm ...
    (freebsd-questions)
  • Re: Review of FreeBSD 5.4
    ... but not less problems compared to FreeBSD. ... If you like to have a bleeding edge system using debian --- just go ... > the linux kernel suffers. ... When the kernel suffers, everyone who uses ...
    (comp.unix.bsd.freebsd.misc)
  • Re: FreeBSD & Linux distro
    ... as a FreeBSD advocacy the tone of the article should be neutral and all ... do not like Linux and more over I have never used it in my life but I ... Statement of the type BSD appears more stable than Linux is ... fewer FreeBSD advocates make claims like that, however, is part of the ...
    (freebsd-questions)
  • Re: Compare Linux and Freebsd Redux
    ... >> Perhaps the most unsettling 'misinformation' about the FreeBSD vs. ... >> Linux situation was the spin that Linux was somehow more 'open', ... >> the official Linux tree... ... your own distribution is that the FreeBSD distribution is/was already ...
    (comp.unix.bsd.freebsd.misc)