有些 站要屏蔽ip不让他们访问,做法很多,这里只介绍用iptables来屏蔽,web屏蔽部分请大家自己去搜,这里就不多说了.
系统:centos 5.5
需要的软件:iptables
1.先下载ip地址文件
我们先到IPdeny下载以国家代码编制好的ip地址列表,比如下载cn.zone:
wget http://www.ipdeny.com/ipblocks/data/countries/cn.zone
2.使用脚本来进行屏蔽
现在有了国家的所有IP地址,要想屏蔽这些 IP 就很容易了,直接写个脚本逐行读取cn.zone文件并加入到iptables中:
#!/bin/bash
# Block traffic from a specific country
# written by blog.slogra.com
COUNTRY = “cn”
IPTABLES = /sbin/iptables
EGREP = /bin/egrep
if [ “$(id -u)” != “0” ]; then
echo “you must be root” 1>&2
exit 1
fi
resetrules() {
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -X
}
resetrules
for c in $COUNTRY
do
country_file = $c.zone
IPS = $($EGREP -v “^#|^$” $country_file)
for ip in $IPS
do
echo “blocking $ip”
$IPTABLES -A INPUT -s $ip -j DROP
done
done
exit 0
夜空- 本站版权
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-250.html

相关资源:Veneer:文件屏蔽软件-开源-其它代码类资源-CSDN文库
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!