- 论坛徽章:
- 0
|
- test.pl
- -----------
- #!/usr/bin/perl
- my(%A,%B);
- my $F1=shift @ARGV;
- my $F2=shift @ARGV;
- for (@ARGV){$B{$_}=1;}
- open(F, "<$F1");
- while(<F>)
- {
- /(\S+)="(\S+)"/;
- $A{$2}=$1;
- }
- close(F);
- open(F,"<$F2");
- OUT:while(<F>)
- {
- chomp;
- split;
- next if scalar @_ != scalar @ARGV *2 + 5;
- while(my($key,$value)=each(%A)){s/\b$key\b/\$$value/;next OUT if ($& eq "" && exists $B{$value}) || ($& ne "" && not exists($B{$value}));}
- print $_,"\n";
- }
- close(F);
复制代码
使用方法
- ./test.pl 文件1 文件2 参数列表
- 比如:
- cat file1
- DIP="192.168.3.1"
- PROTOCOL="tcp"
- DPORT="80"
- cat file2
- cat file2
- iptables -A INPUT -p tcp --dport 80 -d 192.168.3.1 -j DROP
- iptables -A OUTPUT -p udp --dport 80 -d 192.168.3.1 -j DROP
- iptables -A INPUT -d 192.168.3.1 -j DROP
- iptables -I FORWARD -p tcp -d 192.168.3.1 -j DROP
- iptables -I OUTPUT -d 192.168.3.1 -j DROP
- ./test.pl file1 file2 DIP
- iptables -A INPUT -d $DIP -j DROP
- iptables -I OUTPUT -d $DIP -j DROP
- ./test.pl file1 file2 DIP PROTOCOL
- iptables -I FORWARD -p $PROTOCOL -d $DIP -j DROP
- ./test.pl file1 file2 DIP PROTOCOL DPORT
- iptables -A INPUT -p $PROTOCOL --dport $DPORT -d $DIP -j DROP
复制代码 |
|