如何获取电信运营商ip地址分配的详细信息

whois 工具获取

如何获取电信运营商ip地址分配的详细信息
APNIC
是管理亚太地区IP地址分配的机构,它有着丰富准确的IP地址分配库,同时这些信息也是对外公开的!
下面就让我们看看如何在Linux下获得一些电信运营商的IP地址分配情况:
shell> wget http://ftp.apnic.net/apnic/dbase/tools/ripe-dbase-client-v3.tar.gz
shell> tar xzvf ripe-dbase-client-v3.tar.gz
shell> cd whois-3.1
shell> ./configure
shell> make
完成上述编译安装工作后,我们开始获取IP地址段;
中国网通:
shell> ./whois3 -h whois.apnic.net -l -i mb MAINT-CNCGROUP > /var/cnc
中国电信:
shell> ./whois3 -h whois.apnic.net -l -i mb MAINT-CHINANET > /var/chinanet
中国铁通:
shell> ./whois3 -h whois.apnic.net -l -i mb MAINT-CN-CRTC > /var/crtc
打开获取后的文件可以看到里面的信息非常详细,甚至可以看到各个分公司的负责人、电话、电子邮件等等信息。如果想得到一份整齐干净的IP地址段文件,只要用grepawk简单过滤就可以了:)
一个转自CU的自动获取脚本

复制代码
代码如下:
#!/bin/sh
#auto get the IP Table
#get the newest delegated-apnic-latest
rm delegated-apnic-latest
if type wget
then wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest
else fetch http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest
fi
grep 'apnic|CN|ipv4' delegated-apnic-latest | cut -f 4,5 -d '|' | tr '|' ' ' | while read ip cnt
do
mask=$(bc < pow=32;
define log2(x) {
if (x<=1) return (pow);
pow--;
return(log2(x/2));
}
log2($cnt);
END
)
echo $ip/$mask';'>>cnnet
resultext=`whois $ip@whois.apnic.net | grep -e ^netname -e ^descr -e ^role -e ^mnt-by | cut -f 2 -d ':' | sed 's/ *//'`
if echo $resultext | grep -i -e 'railcom' -e 'crtc' -e 'railway'
then echo $ip/$mask';' >> crc
elif echo $resultext | grep -i -e 'cncgroup' -e 'netcom'
then echo $ip/$mask';' >> cnc
if echo $resultext | grep -i -e 'chinanet' -e 'chinatel'
then echo $ip/$mask';' >> telcom_acl
elif echo $resultext | grep -i -e 'unicom'
then echo $ip/$mask';' >> unicom
elif echo $resultext | grep -i -e 'cmnet'
then echo $ip/$mask';' >> cmnet
else
echo $ip/$mask';' >> other_acl
fi
done

以上脚本未测试,自己写了个把netmask计算的脚本

grep 'apnic|CN|ipv4' delegated-apnic-latest | cut -f 4,5 -d '|' | tr '|' ' ' | while read ip netmask
do
i=0;
while [ $netmask -gt 1 ]
do
let "netmask=$netmask/2";
let "i = $i + 1";
done
echo $ip/$i;
done

滚动至顶部