#!/usr/bin/perl -w # Author: Zhuohuan Li <> # Date: 2005-02-23
my $MAX_NUM=10000;
#输出 iptables-restore 数据 #print_iptables_restore();
#输出调用iptables的脚本程序 print_iptables();
sub print_iptables_restore { print “# Generated by gen_rule.pl v1.0 on ” . `date`; print ‘# by Zhuohuan Li <> 2005-02-23′ . “
”; print “*filter
”; print “:zixia - [0:0]
”;
for ( $n=0; $n<$MAX_NUM; $n++ ){ print “-A zixia “ . random_rule() . “
”; }
print “COMMIT
”; print “# Completed on ” . `date`; }
sub print_iptables { for ( $n=0; $n<$MAX_NUM; $n++ ){ print “iptables -A zixia “ . random_rule() . “
”; if ( 0==$n%100 ){ print “date
”; } } }
sub random_rule { return ” -p ” . random_protocol() . ” -s ” . random_ip() . ” –sport ” . random_port() . ” -d ” . random_ip() . ” –dport ” . random_port() #. ” -m time –timestart ” . random_clocktime() #. ” –timestop ” . random_clocktime() #. ” –days ” . random_day() . ” -j ” . random_target()
}
sub random_ip { return int(rand(255)) . ‘.’ . int(rand(255)) . ‘.’ . int(rand(255)) . ‘.’ . int(rand(255)) ; }
sub random_port { return int(rand(65536)); }
sub random_day { return (’Fri’,'Tue’,'Wed’,'Thu’,'Fri’,'Sat’,'Sun’)[int(rand(7))]; }
sub random_clocktime { return
(’0:00′,’1:00′,’2:00′,’3:00′,’4:00′,’5:00′,’6:00′,’7:00′,’8:00′,’9:00′,’10:00′,’11:00′,’12:00′,’13:00′,’14:00′,’15:00′,’16:00′,’17:00′,’18:00′,’19:00′,’20:00′,’21:00′,’22:00′,’23:00′)[int(rand(24))]; }
sub random_protocol { return (’tcp’,'udp’)[int(rand(2))]; }
sub random_target { return (’ACCEPT’,'DROP’,'RETURN’)[int(rand(3))]; }
|