统计当前Win32系统上的TCP链接类型和数目的程序:
#!perl -w
use strict;
my %state =();
my @lines = split("\n", `netstat -n -a`);
foreach (@lines)
{
my $addr = "([0-9]+).([0-9]+).([0-9]+).([0-9]+):([0-9]+)";
if ($_ =~ /TCP[\s]+$addr[\s]+$addr[\s]+([\w]+)/)
{
$state{$11}++;
}
}
my ($key, $value);
print "$key=$value\n" while (($key,$value) = each %state);
结果如下图:
阅读(1045) | 评论(0) | 转发(0) |