Shell obtains the network segment scripts of major carriers in China.

Source: Internet
Author: User
Asia Pacific Network Information is recorded here and updated every day. Bytes. #! /Bin/sh # autogettheIPTable # getthen

Asia Pacific Network Information is recorded here and updated every day.

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

 

The script below will edit the text and output the CIDR blocks of several major carriers in China.

 

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

Related Article

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.