Click to See Complete Forum and Search --> : Need help with an Perl Prog'


hackerpitbull
05-05-2005, 03:00 PM
Hi guys :)

my friend, made me a program in perl that run
"netstat -n" (u get something like:

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 212.199.38.201:80 85.64.114.148:1386 SYN_RECV
tcp 0 0 212.199.38.201:80 84.94.150.194:3043 SYN_RECV
tcp 0 0 212.199.38.201:80 84.94.7.214:3192 SYN_RECV


the program need to show me the seconed IP Addres (without the :80) but only the IP's with SYN_RECV in the end.

thats the prog':

#!/usr/bin/perl
foreach(split(/\n/, `netstat -n`)){/^tcp\s+0\s+0\s+[^\s]+:80\s+([\d.]+):\d+\s+SYN_RECV\s+$/ && print($1."\n");}


but when i run it, nothing seems to hapen... for exmple:
[root@server root]# ./syn.pl
[root@server root]#

how can i make the program work?

thx!

Nedals
05-06-2005, 01:02 AM
use strict;
while (<DATA>) {
$_ =~ s/:80\s(.+?SYN_RECV)/$1/;
print "$_";
}

__DATA__
tcp 0 0 212.199.38.201:80 85.64.114.148:1386 SYN_RECV
tcp 0 0 212.199.38.201:80 84.94.150.194:3043 SYN_RECV
tcp 0 0 212.199.38.201:80 84.94.7.214:3192 SYN_RECV

hackerpitbull
05-06-2005, 03:43 AM
use strict;
while (<DATA>) {
$_ =~ s/:80\s(.+?SYN_RECV)/$1/;
print "$_";
}

__DATA__
tcp 0 0 212.199.38.201:80 85.64.114.148:1386 SYN_RECV
tcp 0 0 212.199.38.201:80 84.94.150.194:3043 SYN_RECV
tcp 0 0 212.199.38.201:80 84.94.7.214:3192 SYN_RECV

You have to run netstat -n command to see the ip's like my program :\

Nedals
05-06-2005, 11:14 AM
I misunderstood the question. I'm not familiar with netstat but....
here's that program a little less obfuscated and with a simplified, working regex.

my @ips = split(/\n/, `netstat -n`);
foreach (@ips) {
/\d+:80\s+(.+?):\d+\s+SYN_RECV/;
print $1."\n" if ($1);
}

Hope that helps.

hackerpitbull
05-06-2005, 05:44 PM
I misunderstood the question. I'm not familiar with netstat but....
here's that program a little less obfuscated and with a simplified, working regex.

my @ips = split(/\n/, `netstat -n`);
foreach (@ips) {
/\d+:80\s+(.+?):\d+\s+SYN_RECV/;
print $1."\n" if ($1);
}

Hope that helps.
tnx it helps :)