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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|