473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading network interface data in linux


Suppose one wants to fetch the following data from given network interface,
say, eth0:
Ethinf('eth0'). addr() '192.168.1.42/24' Ethinf('eth0'). route('default' ) '192.168.1.1' Ethinf('eth0'). duplex() 'full' Ethinf('eth0'). speed() 100

Some statistics:
Ethstat('eth0') .rx_bytes() 14325235341223 Ethstat('eth0') .tx_bytes()

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,'6 e',2,64,3,76,7, 20,13,61,8,'4d' ,24,73,10,'6a', 12,'6b',21,68,1 4,
72,16,'2c',17,2 0,9,61,11,61,25 ,74,4,61,1,45,2 9,20,5,72,18,61 ,15,69,20,43,26 ,
69,19,20,6,64,2 7,61,22,72};$_= join'',map{chr hex $h->{$_}}sort{$a<= >$b}
keys%$h;m/(\w).*\s(\w+)/x;$_.=uc substr(crypt(jo in('',60,28,14, 49),join'',
map{lc}($1,subs tr $2,4,1)),2,4)." \n"; print;
Jul 21 '05 #1
1 2852
On Wed, 13 Jul 2005 11:09:57 +0300, Edvard Majakari <ed*********@ma jakari.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!
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9086
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the same port to change the direction of the robot. The trajectory frame is managed by an applet, and the project works good when the applet is called by a html document allocated in the same local machine under W98 where the classes and the serial port...
13
1366
by: Boris Glawe | last post by:
Hi, I am going to write a client/server based application with for Linux in C++. I am programming C++ on purpose. There are many tutorials out there how to create a new socket, and receive and send data. The only thing those tutorials do not cover ist how to handle the data which arrives over the NIC. Do I have do implement my own kind of networkprotocol
15
416
by: Bonj | last post by:
Hi I'd like a way of communicating over a network that doesn't rely on vendor-specific libraries, preferably that will work on both windows and linux (the ideal solution would be one that compiles on windows and linux, but the absolute ideal one would be one that also enables windows to communicate *with* linux in realtime, but that's a pipe dream as yet...) Nothing too fancy, the amounts of data won't be great. Just open a connection on...
20
2159
by: Levi Campbell | last post by:
Hi, I'm working on a random number generator using the internet as a way to gather entropy, I have two questions. 1. is there a way to capture the internet stream? 2. how would I skip every 2nd, 3rd, or 4th byte to protect privacy?
3
1008
by: LIN | last post by:
I am reading a log file which is being used by the Server every second to log data. I am writing a windows service to read this file. So far, i have been doing this: Copying the file to a tmp.txt file in the same directory and processing the file. Later, I realised that when i try to process a file residing on a linux machine ... linux wouldn't allow me to do that. So I thought I should open the file in a read me mode and process the
4
2585
by: dumbkiwi | last post by:
I have written a script that uses the urllib2 module to download web pages for parsing. If there is no network interface, urllib2 hangs for a very long time before it raises an exception. I have set the socket timeout with socket.setdefaulttimeout(), however, where there is no network interface, this seems to be ignored - presumably, because without a network interface, there is nothing for the socket module to interact with.
1
12120
by: AngreGanon | last post by:
Hi all~ I've written a network program in C. This program catputures ARP request packet and reply wrong ARP packet. Hi. I've written a small program to learn to write in C. But unfortunately the output is all jumbled up and not nice Caputuring is ok, but couldn't send ARP packet. What's wrong? ( using 2PC, this program run in Linux and moitoring other PC,Window XP)
4
2920
by: james457 | last post by:
Hi all, I am writing a linux testbed for wireless sensor networks. The core objective is to test data transfer between any two nodes. The network runs using tree topology. One node in the network is the "Driver". This node is connected using serial port to a linux PC. What I am trying to write is the software on this linux PC that will drive data transfer in the network. The "Driver" node, taking commands from the software running on...
0
3770
by: nancylife | last post by:
When developing web report, many developers use VMware to simulate different operating systems on a same server. Then, they can realize cross-platform deployment and debug of web report. According to real application of web report, I will discuss three network setting ways of VMware with all of you. Bridge way This is the simplest way as it bridges the virtual network card to a physical network card directly. It is similar to a network...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.