#! D:\perl\bin\perl # # CGI script to display the status of tcp/udp/raw connections on the server. # 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"; } } }