Reading network interface data in linux

Jorgen Grahn jgrahn-nntq at algonet.se
Sat Jul 23 08:45:11 EDT 2005


On Wed, 13 Jul 2005 11:09:57 +0300, Edvard Majakari <edvard+news at majakari.net> wrote:
>
> Suppose one wants to fetch the following data from given network interface,
> say, eth0:
>
>>>> Ethinf('eth0').addr()
> '192.168.1.42/24'
...
>>>> Ethstat('eth0').rx_bytes()
> 14325235341223
...
> One could implement modules by installing eg. ethtool and reading speed/duplex
> information by parsing ethtool output, but it is ugly way to do it, prone to
> errors, requires launching a process as well as installation of ethtool.

On the other hand, I have a hunch that the interface that ethtool uses is
unstable, changes between major kernel versions, varies with the kind of
hardware you have, etc.

If that is the case, you might want to keep parsing ethtool's output. Letting
/them/ worry about tracking kernel changes would actually be the most stable
solution.  The ethtool authors are kernel developers, and probably know all
that stuff.

Or convince the ethtool authors to release future ethtool versions as a
Python module with an optional command-line interface ;-)

/Jorgen

-- 
  // Jorgen Grahn <jgrahn@       Ph'nglui mglw'nafh Cthulhu
\X/                algonet.se>   R'lyeh wgah'nagl fhtagn!



More information about the Python-list mailing list