Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I am trying to fix a little utility i created to diaply the `netstat -an` info and maybe play with that info by i don't know, getting a hostname. The script works fine but it's not working as i expected. Heres the code:
#! D:\perl\bin\perl # # CGI script to display the status of tcp/udp/raw connections on the s +erver. # Will give you a warning is there are any SYN'ers. BEGIN { use strict; print "Content-Type: text/plain\n\n"; use CGI::Carp 'fatalsToBrowser'; use warnings; } &netstat('-an'); sub netstat { my $args = shift; my $line; my @lines = `netstat $args`; print "$0: running \'netstat $args\'\n\n"; my($prot,$laddr,$lport,$eaddr,$eport,$status,$syn); LOOP: foreach $line (@lines) { $_ = $line; next LOOP if /^Active Connections/; next LOOP if /^$/; next LOOP if /^\s+Proto/; if(/^\s+(.*)\s+(.*):(.*)\s+(.*):(.*)\s+(.*)/) { $prot = $1; $laddr = $2; $lport = $3; $eaddr = $4; $eport = $5; $status = $6; $syn = 0; if($status =~ /syn/i) { $syn = $status; } print "\nwarning: $status! I think we're being SYN'ed\n\n" + if $syn; print "Local: $laddr:$lport - External: $eaddr:$eport - ", +$syn || $status,"\n"; } } }
All i need to do is clean it up and get rid of the spaces. Heres a sample netstat line from the script: Local: 0.0.0.0:7 - External: 0.0.0.0:0 LISTENING -
And heres one from the netstat command TCP 0.0.0.0:81 *:* LISTENING
Any pointers and that kinda stuff would be great.
Cheers
Elfyn McBratney
Edit kudra, 2002-06-08 Changed title
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem with regex
by stefp (Vicar) on Jun 08, 2002 at 04:50 UTC | |
|
Re: problem with regex
by grep (Monsignor) on Jun 08, 2002 at 07:00 UTC | |
|
Re: problem with regex to extract netstat info
by Util (Priest) on Jun 08, 2002 at 22:10 UTC |