免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1480 | 回复: 0
打印 上一主题 下一主题

获得国内IP地址列表 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-25 14:42 |只看该作者 |倒序浏览

                由于项目实验需求,需要只能针对国内主机提供服务,这就需要有一份国内IP地址的列表。
首先需要得到国内的IP列表,我们通过apnic查到国内的IP列表。
http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst
可以写一个简单的脚本:
# wget -q -O - http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst | grep cn | awk '{print $5}' > cn.txt
这样cn.txt中就是所有的国内网段。
然后写了一个fw.sh的脚本,里面INPUT的默认处理策略是DROP,然后允许局域网地址和部分公网地址的访问,允许远程管理网段的22端口访问,然后就是ACCEPT国内的IP列表。
#!/bin/sh
IPT=/sbin/iptables
LOCAL_RANGE=192.168.1.0/24
INET_RANGE=1.2.3.0/24
REMOTE_ADMIN_RANGE=4.3.2.0/24
#Clean The Old Tables
for TABLE in filter nat mangle ; do
    $IPT -t $TABLE -F
        $IPT -t $TABLE -X
done
$IPT -P INPUT DROP
$IPT -P OUTPUT ACCEPT
$IPT -A INPUT -s $LOCAL_RANGE -j ACCEPT
$IPT -A INPUT -s $INET_RANGE -j ACCEPT
$IPT -A INPUT -p tcp -s $REMOTE_ADMIN_RANGE --dport 22 -j ACCEPT
$IPT -A INPUT -p tcp --dport 22 -j DROP
#Enable TCP SYN Cookie Protection
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
########################################################
#Stealth Scans and TCP State Flags
#All of the bits are cleared
$IPT -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
#SYN and FIN are both set
$IPT -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
#SYN and RST are both set
$IPT -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
#FIN and RST are both set
$IPT -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j DROP
#FIN is the only bit set,without the expected accompanying ACK
$IPT -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j DROP
#PSH is the only bit set,without the expected accompanying ACK
$IPT -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j DROP
#URG is the only bit set,without the expected accompanying ACK
$IPT -A INPUT -p tcp --tcp-flags ACK,URG URG -j DROP
#############################################################
# ICMP Control and Status Message
$IPT -A INPUT --fragment -p icmp -j DROP
$IPT -A OUTPUT --fragment -p icmp -j DROP
###########################################################
#Using Connection State to by-pass Rule Checking
$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A INPUT -m state --state INVALID -j DROP
$IPT -A OUTPUT -m state --state INVALID -j DROP
###########################################################
#China NetRange
# wget -c http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst
# grep cn country-ipv4.lst | awk '{print $5}' > cn.txt
while read iprange
do
    $IPT -A INPUT -s $iprange -j ACCEPT
done
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/12592/showart_2077912.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP