Easy access to the IP address allocation segment of Netcom, Telecom and CRC-application techniques

Source: Internet
Author: User
Tags dbase pow
Sometimes some of the projects and applications across the network, need to be as accurate as possible to know telecommunications, Netcom, railcom and other telecommunications operators IP address segment distribution, can be online information is not only very small, and often are n months ago, outdated information ...
APNIC is the organization that manages IP address assignment in Asia-Pacific region, which has a rich and accurate IP address allocation library, and this information is also open to the outside world! Let's take a look at how to get some telecom operators ' IP address distribution under Linux:
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
After completing the above compilation and installation work, we begin to obtain the IP address segment;
China Netcom:
shell>/whois3-h whois.apnic.net-l-i mb maint-cncgroup >/VAR/CNC
Telecom:
shell>/whois3-h whois.apnic.net-l-i mb maint-chinanet >/var/chinanet
China railcom:
shell>/whois3-h whois.apnic.net-l-i mb MAINT-CN-CRTC >/VAR/CRTC
Open the acquired file can see the information inside very detailed, and even see the various branches of the owner, phone, e-mail and so on information. If you want a neat, clean IP address segment file, simply filter with grep and awk:

An automatic fetch script for conversion from CU:
Copy Code code as follows:

#!/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
Todo
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.