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.


In reply to Re: How to monitor internet speed in real time? by ambrus
in thread How to monitor internet speed in real time? by rockmountain

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.