IPB=/sbin/iptables $IPB -F INPUT for kk in ` cat ip.txt | awk '{printf ("%s_%s\n",$1,$2)}'` do #echo $kk startip=`echo $kk | awk -F "_" '{print $1}'` endip=`echo $kk | awk -F "_" '{print $2}'` $IPB -A INPUT -p tcp --dport 80 -m iprange --src-range $startip-$endip -j ACCEPT done ### deny all $IPB -A INPUT -p tcp --dport 80 -j DROP
ip.txt内容是
1.0.1.0 1.0.3.255 768
1.0.8.0 1.0.15.255 2,048
1.0.32.0 1.0.63.255 8,192