u235sentinel has asked for the wisdom of the Perl Monks concerning the following question:

I've been looking around for a Perl module that will allow me to pull netstat summary information. I've looked around CPAN and have discussed it in the Perl beginners mail list. So far, nobody I've spoken with is aware of any module that will do this.

Basically I want to grab specific information from the netstat summary and print it out in Perl. ICMP and TCP information mainly.

Is this possible? I'm up to the challenge of writing my own Perl code and come up with something that will do this. I was hoping there might be a module out already.

Thx

Replies are listed 'Best First'.
Re: Netstat summary and Perl?
by kvale (Monsignor) on Apr 07, 2004 at 16:31 UTC
      Thanks for pointing out the snippet! I looked through it quickly and it gave me some good ideas.

      I'm looking at writing code to parse the summary information actually. netstat -s provides summary information about ICMP, TCP, UDP and so on. I'm interested in capturing infomation such as dropped packets and errors. I was hoping to stay within Perl and not externally call netstat.

      For example, instead of calling date I would use Perl's localtime. I was hoping there was a module for Perl that would gather the netstat summary (netstat -s equivalent).

Re: Netstat summary and Perl?
by blue_cowdawg (Monsignor) on Apr 07, 2004 at 16:41 UTC

        Is this possible? I'm up to the challenge of writing my own Perl code and come up with something that will do this. I was hoping there might be a module out already.

    That's a rather vague question. It all depends on what you are trying to do on one hand and on the other my visceral response is "there's damn little that isn't possible in Perl."

    Is there a specific set of information you are trying to glomb or are you just trying to slurp and process the whole output?

      I was looking at gathering specific bits of information from the TCP and ICMP summary information. I didn't give specific information beyond this mainly because I'm debating which pieces I want.

      I was thinking of items such as retransmissions, failed connections and packets discarded. There is more I may want to capture and process. Right now I'm scoping the needs and what is available. Thx

            Right now I'm scoping the needs and what is available.

        And you aren't giving me much to work with.

        However, let's look at retransmissons for a second. Just like I taught myself how to translate or search for what information I need in the output of the command I am going to do the same for Perl:

        : : some handwaving... : open PIPE,"netstat -s |" or die $!; my @slurp=<PIPE>; close PIPE; chomp @slurp; grep /Retran/,@slurp; printf "%s\n",join("\n",@slurp); : :
        is going to yeild me something like:
        TCPLostRetransmit: 0 TCPFastRetrans: 0 TCPForwardRetrans: 0 TCPSlowStartRetrans: 0

        What you do beyond that depends on your requirements. I recommend you sit down and develop your requirements thoroughly and then plan your attack rather than fit your requirements to your attack. :-)

        I hope this isn't homework!