http://qs321.pair.com?node_id=172761

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

Hi,

I have a problem with this regex. It seems to keep the spaces when i thought the \s+ part would not catch them.

Hers 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"; } } }

Cheers,

Elfyn