Reading network interface data in linux

E

Edvard Majakari

Suppose one wants to fetch the following data from given network interface,
say, eth0:
100

Some statistics:
2513152423

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.

As for the byte counts, you could get all information ifconfig show by reading
/proc/net/dev (which is more nice to parse), but it seems like those counters
are 32-bit, and they wrap around quite quickly in a 1000 gbit network (~30
seconds).

I was wondering is there really no module implemented which already does those
things?

I've already implemented a proto by doing exactly as I told (parsing ethtool &
/proc/net/dev), but I strive for more elegant solution. I'm willing to join
the effort with someone else, if possible.

--
#!/usr/bin/perl -w
$h={23,69,28,'6e',2,64,3,76,7,20,13,61,8,'4d',24,73,10,'6a',12,'6b',21,68,14,
72,16,'2c',17,20,9,61,11,61,25,74,4,61,1,45,29,20,5,72,18,61,15,69,20,43,26,
69,19,20,6,64,27,61,22,72};$_=join'',map{chr hex $h->{$_}}sort{$a<=>$b}
keys%$h;m/(\w).*\s(\w+)/x;$_.=uc substr(crypt(join('',60,28,14,49),join'',
map{lc}($1,substr $2,4,1)),2,4)."\n"; print;
 
J

Jorgen Grahn

Suppose one wants to fetch the following data from given network interface,
say, eth0:

....
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,237
Latest member
AvivMNS

Latest Threads

Top