輕松獲得網(wǎng)通、電信、鐵通IP地址分配段的方法
更新時(shí)間:2007年11月09日 20:11:57 作者:
有時(shí)搞一些跨網(wǎng)段的工程和應(yīng)用,需要盡量準(zhǔn)確的知道電信、網(wǎng)通、鐵通等電信運(yùn)營(yíng)商的IP地址段分配情況,可網(wǎng)上的資料不但很少,而且經(jīng)常都是N個(gè)月前的過(guò)期資料……
APNIC是管理亞太地區(qū)IP地址分配的機(jī)構(gòu),它有著豐富準(zhǔn)確的IP地址分配庫(kù),同時(shí)這些信息也是對(duì)外公開(kāi)的!下面就讓我們看看如何在Linux下獲得一些電信運(yùn)營(yíng)商的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
完成上述編譯安裝工作后,我們開(kāi)始獲取IP地址段;
中國(guó)網(wǎng)通:
shell> ./whois3 -h whois.apnic.net -l -i mb MAINT-CNCGROUP > /var/cnc
中國(guó)電信:
shell> ./whois3 -h whois.apnic.net -l -i mb MAINT-CHINANET > /var/chinanet
中國(guó)鐵通:
shell> ./whois3 -h whois.apnic.net -l -i mb MAINT-CN-CRTC > /var/crtc
打開(kāi)獲取后的文件可以看到里面的信息非常詳細(xì),甚至可以看到各個(gè)分公司的負(fù)責(zé)人、電話、電子郵件等等信息。如果想得到一份整齊干凈的IP地址段文件,只要用grep和awk簡(jiǎn)單過(guò)濾就可以了:)
一個(gè)轉(zhuǎn)自CU的自動(dòng)獲取腳本 :
#!/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
APNIC是管理亞太地區(qū)IP地址分配的機(jī)構(gòu),它有著豐富準(zhǔn)確的IP地址分配庫(kù),同時(shí)這些信息也是對(duì)外公開(kāi)的!下面就讓我們看看如何在Linux下獲得一些電信運(yùn)營(yíng)商的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
完成上述編譯安裝工作后,我們開(kāi)始獲取IP地址段;
中國(guó)網(wǎng)通:
shell> ./whois3 -h whois.apnic.net -l -i mb MAINT-CNCGROUP > /var/cnc
中國(guó)電信:
shell> ./whois3 -h whois.apnic.net -l -i mb MAINT-CHINANET > /var/chinanet
中國(guó)鐵通:
shell> ./whois3 -h whois.apnic.net -l -i mb MAINT-CN-CRTC > /var/crtc
打開(kāi)獲取后的文件可以看到里面的信息非常詳細(xì),甚至可以看到各個(gè)分公司的負(fù)責(zé)人、電話、電子郵件等等信息。如果想得到一份整齊干凈的IP地址段文件,只要用grep和awk簡(jiǎn)單過(guò)濾就可以了:)
一個(gè)轉(zhuǎn)自CU的自動(dòng)獲取腳本 :
復(fù)制代碼 代碼如下:
#!/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
相關(guān)文章
十萬(wàn)美元的懸賞 互聯(lián)網(wǎng)梅森素?cái)?shù)大搜索
十萬(wàn)美元的懸賞 互聯(lián)網(wǎng)梅森素?cái)?shù)大搜索...2007-06-06intel原裝主版沒(méi)有驅(qū)動(dòng)的查找技巧
intel原裝主版沒(méi)有驅(qū)動(dòng)的查找技巧...2007-05-05ftp上傳時(shí)數(shù)據(jù)Socket錯(cuò)誤連接超時(shí)的解決方法
ftp上傳時(shí)數(shù)據(jù)Socket錯(cuò)誤連接超時(shí)的解決方法...2007-07-07收藏的word實(shí)用技巧問(wèn)題解答(實(shí)用)
收藏的word實(shí)用技巧問(wèn)題解答(實(shí)用)...2007-03-03Service Unavailable產(chǎn)生的原因
Service Unavailable產(chǎn)生的原因...2007-04-04QQ卡機(jī)問(wèn)題解決方法(信息記錄過(guò)大時(shí))
QQ卡機(jī)問(wèn)題解決方法(信息記錄過(guò)大時(shí))...2007-02-02搞定windows關(guān)機(jī)慢 等待時(shí)間過(guò)長(zhǎng)的問(wèn)題
長(zhǎng)期以來(lái),Windows 系統(tǒng)緩慢的關(guān)機(jī)速度一直為人詬病,用戶往往需要等待很長(zhǎng)時(shí)間才能把系統(tǒng)關(guān)閉,這一問(wèn)題在Windows Vista中也沒(méi)有得到很好的解決2008-08-08