交给你轻松获得网通、电信、铁通IP地址分配段的方法
有时搞一些跨网段的工程和应用,需要尽量准确的知道电信、网通、铁通等电信运营商的IP地址段分配情况,可网上的资料不但很少,而且经常都是N个月前的过期资料……
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地址段文件,只要用grep和awk简单过滤就可以了:)
一个转自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
<<END
|
tail
-1
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
以上是您精心准备的的内容,以便于您获取更多的相关知识。