netstat -an |awk '/^tcp/{a[$NF]++}END{for (b in a)print b,a[b]}'
#!/usr/bin/perl
use warnings;
use strict;
my (%tcp,$netstat);
for my $line (`netstat -an`){
if ( $line =~ /^tcp/ ){
$netstat=(split /\s+/,$line)[5];
++$tcp{$netstat};
}
}
sub sort_tcp {
$tcp{$a} <=> ${tcp}{$b};
}
for my $key (sort sort_tcp keys %tcp){
chomp $key;
printf "%-20s=>%20d\n",$key,$tcp{$key};
}
阅读(1960) | 评论(0) | 转发(0) |