How to easily obtain CIDR blocks of China Netcom, China Telecom, and China tietong

Source: Internet
Author: User
Tags dbase

Sometimes it is necessary to know the IP address segment distribution of telecom, China Netcom, China tietong and other telecom operators as accurate as possible for cross-network segment engineering and applications. However, there are few materials available on the Internet, in addition, it is often the expiration date of N months ago ......
APNIC is an organization that manages IP Address Allocation in the Asia Pacific region. It has a rich and accurate IP Address Allocation library, and this information is also made public to the public! Next let's take a look at how to obtain the IP address distribution of some telecom operators in 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, we start to get the IP address segment;
China Netcom:
Shell>./whois3-h whois.apnic.net-l-I mb MAINT-CNCGROUP>/var/cnc
China Telecom:
Shell>./whois3-h whois.apnic.net-l-I mb MAINT-CHINANET>/var/chinanet
China tietong:
Shell>./whois3-h whois.apnic.net-l-I mb MAINT-CN-CRTC>/var/crtc
When you open the obtained file, you can see that the information in it is very detailed, and even the owner, phone number, email, and other information of each branch. If you want to get a neat and clean IP address segment file, you only need to use grep and awk for simple filtering :)

An Automatic Acquisition script for conversion from CU:Copy codeThe Code is 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
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 'cmtnet'
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.