- 论坛徽章:
- 0
|
应该可以,就是变量名称起的有点乱~ - my %hash;
- my %rhash;
- open IN,"<source.txt";
- while (<IN>) {
- chomp;
- if (/^(\w{3})\/(\S+):(\d+)$/){
- push @{$hash{$1}{$2}},$3;
- push @{$rhash{$1}{$3}},$2;
- }
- }
- close IN;
- foreach my $k (keys %rhash){
- foreach my $k1 (keys %{$rhash{$k}}) {
- delete $rhash{$k}{$k1} if @{$rhash{$k}{$k1}}==1;
- }
- }
- foreach my $kk (keys %hash){
- foreach my $kk1 (keys %{$hash{$kk}}) {
- foreach my $kk2 (keys %{$rhash{$kk}}) {
- delete $hash{$kk}{$kk1} if @{$hash{$kk}{$kk1}}==1 and $hash{$kk}{$kk1}->[0] eq $kk2;
- }
- }
- }
- foreach my $pkk (keys %hash){
- foreach my $pkk1 (keys %{$hash{$pkk}}) {
- if (@{$hash{$pkk}{$pkk1}} >1){
- printf "-p %s -m multiport --sports %s --dports %s\n",$pkk,$pkk1,join ",",@{$hash{$pkk}{$pkk1}};
- } else {
- printf "-p %s --sport %s --dport %s\n",$pkk,$pkk1,$hash{$pkk}{$pkk1}->[0];
- }
- }
- }
- foreach my $rkk (keys %rhash){
- foreach my $rkk1 (keys %{$rhash{$rkk}}) {
- printf "-p %s -m multiport --sports %s --dports %s\n",$rkk,(join ",",@{$rhash{$rkk}{$rkk1}}),$rkk1;
- }
- }
复制代码 |
|