口水妞网首页
  • Linux下获得中国基础电信运营商(网通、电信、教育网)的IP地址分配情况

    2011-2-26 9:41:25 管理员
    Linux下获得中国基础电信运营商(网通、电信、教育网)的IP地址分配情况
     

    APNIC是管理亚太地区IP地址分配的机构,它有着准确的IP地址分配库,同时这些信息对外公开,并提供查询工具。

    [mike@vmware ~]$ wget http://ftp.apnic.net/apnic/dbase/tools/ripe-dbase-client-v3.tar.gz
    [mike@vmware ~]$ tar xzvf ripe-dbase-client-v3.tar.gz
    [mike@vmware ~]$ cd whois-3.1
    [mike@vmware ~]$ ./configure --prefix=/opt/whois3
    [mike@vmware ~]$ make
    [mike@vmware ~]$ su -
    Password:
    root@vmware:~# make install

    完成上述编译安装工作后,我们开始获取IP地址段;

    中国网通:

    引用
    root@vmware:~# /opt/bin/whois3 -h whois.apnic.net -l -i mb MAINT-CNCGROUP > /var/cnc



    中国电信:

    引用
    root@vmware:~# /opt/bin/whois3 -h whois.apnic.net -l -i mb MAINT-CHINANET > /var/chinanet


    跨网段的工程和应用中需要尽量准确的知道电信、网通、铁通等电信运营商的IP地址段分配情况
    APNIC是管理亚太地区IP地址分配的机构,它有着丰富准确的IP地址分配库,同时这些信息也是对外公开的。
    在Linux下安装个whois可以轻松获得一些电信运营商的IP地址分配情况:

    [coomix@goome common]$ wget http://ftp.apnic.net/apnic/dbase/tools/ripe-dbase-client-v3.tar.gz
    [coomix@goome common]$ tar xzvf ripe-dbase-client-v3.tar.gz
    [coomix@goome common]$ cd whois-3.1
    [coomix@goome whois-3.1]$ ./configure
    [coomix@goome whois-3.1]$ make
    编译安装后,获取IP地址段:
    中国网通:
    [coomix@goome whois-3.1]$ ./whois3 -h whois.apnic.net -l -i mb MAINT-CNCGROUP > /home/common/cnc
    中国电信:
    [coomix@goome whois-3.1]$  ./whois3 -h whois.apnic.net -l -i mb MAINT-CHINANET > /home/common/chinanet
    中国铁通:
    [coomix@goome whois-3.1]$  ./whois3 -h whois.apnic.net -l -i mb MAINT-CN-CRTC > /home/common/crtc
    [coomix@goome whois-3.1]$

    [coomix@goome common]$ du -sh *
    748K    chinanet 电信ip
    1.3M    cnc      网通ip
    312K    crtc     铁通ip


    打开获取后的文件可以看到里面的信息非常详细,甚至可以看到各个分公司的负责人、电话、电子邮件等等信息。
    inetnum:      202.96.214.192 - 202.96.214.255
    netname:      EGSHOL
    descr:        Education Garden on ShangHai OnLine;
    descr:        ShangHai P&T member University
    country:      CN
    admin-c:      YY6-AP
    tech-c:       XU1-AP
    mnt-by:       MAINT-CHINANET
    changed:      sptwxl@online.sh.cn       19970720
    status:       ASSIGNED NON-PORTABLE
    source:       APNIC
    changed:      hm-changed@apnic.net  20020827

    如果想得到一份整齐干净的IP地址段文件,只要用grep和awk简单过滤就可以了:)

    以下是一个网上的脚本
    #!/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
    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
     



Copyright © 2010 nm.koushuiniu.com. All Rights Reserved. 口水妞网
口水妞网