in reply to How to monitor internet speed in real time?

Your question is not really exact.

Are you trying to monitor internet traffic of a certain machine from the machine itself, or from a different machine? Do you want to mesure all network usage or only that to certain destinations, protocols, ports or programs? And most importantly, what OS are you using?

Anyway, here's some starting point for linux. In linux, there is a counter that counts the total incoming and outgoing bytes on a network interface. You access this counter with the ifconfig program, or directly from /proc/net/dev (this is linux 2.4.25, the /proc interface might be different in other versions). If you read that counter every few seconds, you can see how much data comes in and out.

If you need more detailed statistics, you have to use iptables. Every iptables rule has a byte counter similar to that above. To read this, you run iptables -L -nvx or figure out how iptables gets the data from the kernel. The drawback of this is that iptables requires root permissions, while netstat ifconfig (Update: I meant to say ifconfig here, just as above) does not normally.

Update: see also Re: measuring IN/OUT traffic on your computer which is about the same problem but has code.

  • Comment on Re: How to monitor internet speed in real time?

Replies are listed 'Best First'.
Re^2: How to monitor internet speed in real time?
by rockmountain (Sexton) on Oct 06, 2004 at 07:26 UTC
    http://speedcheck2.optonline.net/speedcheck/speedcheck.html This link shows first roadmap to what I want to implement. In disassembly I find out that it uses javascript and uses Microsoft API. I am not clear about the algorithm implemented. But sure it checks the rate of packets flow. What I really want to do is to somehow monitor the performance of my Cable Operator and store the information in a database. I am able to execute netstat, but trying hard to find a way to use those information contained in the packets. Please enlighten me in this area. And it is my personal belief or you can say it a jingoism that Perl is a better solution provider then that idiotically slow java and javascript
    cheers Rock

      I couldn't view the webpage you've given, so I don't know if it mesures the network usage of your computer or only the speed of the connection of your computer and their server (which can be a good approximation of your internet access bandwidth if you're not downloading anything the same time you're running the speedcheck).

      Netstat is not relevant here. I meant to say ifconfig from the start, but I was tired and said netstat instead in the last paragraph.

      About ifconfig. On my system it prints a line like this about the eth0 interface.

      RX bytes:466213 (455.2 Kb) TX bytes:40233 (39.2 Kb)
      (I've just started my machine so that's why the numbers are so small.) I remember that some older versions of ifconfig does not print this info, probably because this feature was not available in older (2.2) kernels. The command corresponding to ifconfig in windows is ipconfig but I don't know whether it prints this info.