轻松获得网通、电信、铁通IP地址分配段的方法_应用技巧教程-查字典教程网
轻松获得网通、电信、铁通IP地址分配段的方法
轻松获得网通、电信、铁通IP地址分配段的方法
发布时间:2016-12-26 来源:查字典编辑
摘要:有时搞一些跨网段的工程和应用,需要尽量准确的知道电信、网通、铁通等电信运营商的IP地址段分配情况,可网上的资料不但很少,而且经常都是N个月前...

有时搞一些跨网段的工程和应用,需要尽量准确的知道电信、网通、铁通等电信运营商的IP地址段分配情况,可网上的资料不但很少,而且经常都是N个月前的过期资料……

APNIC是管理亚太地区IP地址分配的机构,它有着丰富准确的IP地址分配库,同时这些信息也是对外公开的!下面就让我们看看如何在Linux下获得一些电信运营商的IP地址分配情况:

shell>wgethttp://ftp.apnic.net/apnic/dbase/tools/ripe-dbase-client-v3.tar.gz

shell>tarxzvfripe-dbase-client-v3.tar.gz

shell>cdwhois-3.1

shell>./configure

shell>make

完成上述编译安装工作后,我们开始获取IP地址段;

中国网通:

shell>./whois3-hwhois.apnic.net-l-imbMAINT-CNCGROUP>/var/cnc

中国电信:

shell>./whois3-hwhois.apnic.net-l-imbMAINT-CHINANET>/var/chinanet

中国铁通:

shell>./whois3-hwhois.apnic.net-l-imbMAINT-CN-CRTC>/var/crtc

打开获取后的文件可以看到里面的信息非常详细,甚至可以看到各个分公司的负责人、电话、电子邮件等等信息。如果想得到一份整齐干净的IP地址段文件,只要用grep和awk简单过滤就可以了:)

一个转自CU的自动获取脚本:

复制代码 代码如下:

#!/bin/sh

#autogettheIPTable

#getthenewestdelegated-apnic-latest

rmdelegated-apnic-latest

iftypewget

thenwgethttp://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest

elsefetchhttp://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest

fi

grep'apnic|CN|ipv4'delegated-apnic-latest|cut-f4,5-d'|'|tr'|'''|whilereadipcnt

do

mask=$(bc<<END|tail-1

pow=32;

definelog2(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-f2-d':'|sed's/*//'`

ifecho$resultext|grep-i-e'railcom'-e'crtc'-e'railway'

thenecho$ip/$mask';'>>crc

elifecho$resultext|grep-i-e'cncgroup'-e'netcom'

thenecho$ip/$mask';'>>cnc

ifecho$resultext|grep-i-e'chinanet'-e'chinatel'

thenecho$ip/$mask';'>>telcom_acl

elifecho$resultext|grep-i-e'unicom'

thenecho$ip/$mask';'>>unicom

elifecho$resultext|grep-i-e'cmnet'

thenecho$ip/$mask';'>>cmnet

else

echo$ip/$mask';'>>other_acl

fi

done

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新应用技巧学习
    热门应用技巧学习
    网页设计子分类