A while back I got really into monitoring things on my firewall. I have a windowmaker client that can connect to this. The server below is useful for all kinds of things though. I'll post a perl client too (if there's any interest). You can just telnet this, which is kinda fun. :)
#!/usr/bin/perl use IO::Socket; $port = 7654; ## This could really do anything you want... sub print_stuff { open in, "/proc/net/dev"; while(<in>) { print $client "$_" if /eth[01]:/ or /ppp[01]:/; } close in; } ## Run the farqin thing: $bn = `basename $0`; `killall -v -q -1 $bn`; if (fork) { print "Forkin away...\n"; exit 0; } else { $0 = "$bn [$port]"; &open_it; &listen_to_it; } sub open_it { $sock = new IO::Socket::INET ( LocalPort => "$port", Proto => tcp, Reuse => 1, Listen => 1 ) or die "Could not create socket: $!\n"; } sub listen_to_it { while($client = $sock->accept) { &print_stuff; shutdown $client, 2; } }

UPDATE (12/14/06): these days I would do this a bit differently, if I'd do it at all... the following is untested.

use strict; my $server = new MyMonitor( 8000 ); run $server; exit 0; package MyMonitor; use strict; use Net::Server; use base qw(Net::Server); 1; sub run { my $this = shift; $this->SUPER::run( port => $this->{port}, proto => $this->{proto} +); } sub new { my $class = shift; my $this = bless {}, $class; $this->{port} = shift || 3000; $this->{proto} = shift || 'tcp'; return $this; } sub process_request { my $this = shift; my $prop = $this->{server}; open IN, "/proc/net/dev" or die "problem opening procnetdev: $!"; if( $prop->{udp_true} ){ $prop->{client}->send($_, 0) while <IN>; close IN; return; } print $_ while <IN>; close IN; }

In reply to TCP monitor agent by jettero

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.