- 论坛徽章:
- 7
|
本帖最后由 rubyish 于 2014-01-26 23:15 编辑
biru:- #!/usr/bin/perl -w
- use 5.016;
- my @white_list = qw/180.153.120.101
- 180.153.120.113
- 180.153.120.112
- 180.153.120.114
- 180.153.120.115/;
- my %white_list = map { $_, 1 } @white_list;
- my ( %sip, %tip );
- while (<DATA>) {
- my ( $sip, $tip, $val ) = (split)[ 0, 2, 4 ];
- # if 只 计算 第三列 in 白名单
- # 第三列 not in 白名单 不计算
- # add this line
- next unless exists $white_list{$tip};
- # else delete it
- $sip{$sip}{$tip} += $val;
- $tip{$tip}{$sip} += $val;
- }
- sub Print {
- my ( $file, $hash ) = @_;
- open my $fh, '>', $file or die "$file $!";
- while ( my ( $k, $v ) = each $hash ) {
- my ( $address, $times );
- map { $times += $v->{$_}; $address++ } keys $v;
- say $fh join "\t", $k, $times, $address;
- }
- }
- Print 'sip.txt', \%sip;
- Print 'tip.txt', \%tip;
- __DATA__
- 82.147.223.175 51777 180.153.120.101 80 5
- 199.253.247.3 63281 180.153.120.101 80 5
- 5.108.221.239 54420 180.153.120.112 80 5
- 5.245.102.113 56341 180.153.120.112 80 5
- 146.251.205.200 54455 180.153.120.112 80 5
- 82.147.223.174 60258 180.153.120.112 80 5
- 60.244.63.45 53492 180.153.120.112 80 5
- 41.68.95.115 63476 180.153.120.112 80 5
- 190.148.126.65 59267 180.153.120.112 80 5
- 82.147.223.174 64981 180.153.120.112 80 5
- 182.233.73.219 58633 180.153.120.112 80 5
- 146.251.208.205 56394 180.153.120.112 80 5
- 109.161.243.124 58415 180.153.120.112 80 5
- 37.127.38.128 64862 180.153.120.112 80 5
- 82.147.223.174 51777 180.153.120.111 80 5
- 82.147.223.174 51133 180.153.120.112 80 5
- 82.147.223.174 51873 180.153.120.113 80 5
- 82.147.223.174 51234 180.153.120.114 80 5
- 82.147.223.174 51347 180.153.120.115 80 5
复制代码 |
|