• 自动获取电信/网通等IP列表


    在 ChinaUnix 找到的,利用 whois -A 命令来提取电信/网通信息进而获得相应的网段
    http://bbs.chinaunix.net/viewthread.php?tid=577601
    http://bbs.chinaunix.net/viewthread.php?tid=577598

    1. #!/bin/sh
    2. #filename cn_isp.sh;auto get the IP of CHINANET and CNC;
    3. rm delegated-apnic-latest
    4. rm cnnet
    5. rm IP_CHINANET
    6. rm IP_UNICOM
    7. rm IP_CNC
    8. fetch http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest
    9. grep 'CN|ipv4' delegated-apnic-latest | cut -f 4,5 -d '|' | tr '|' ' ' >> cnnet
    10. cat cnnet | while read ip cnt
    11. do
    12. mask=$(bc < <END | tail -1
    13. pow=32;
    14. define log2(x) {
    15. if (x<=1) return (pow);
    16. pow--;
    17. return(log2(x/2));
    18. }
    19. log2($cnt);
    20. END
    21. )
    22.  
    23. resultext=`whois -A $ip | grep -e ^netname -e ^descr -e ^role | cut -f 2 -d ':' | sed 's/ *//'`
    24. echo '................Search for '$ip/$mask' .........................'
    25.  
    26. if echo $resultext | grep -i -e 'chinanet' -e 'chinatel' -e 'china telecom'
    27.   then echo $ip/$mask >> IP_CHINANET
    28. fi
    29.  
    30. if echo $resultext | grep -i -e 'unicom'
    31.   then echo $ip/$mask >> IP_UNICOM
    32. fi
    33.  
    34. if echo $resultext | grep -i -e 'cncgroup'
    35.   then echo $ip/$mask >> IP_CNC
    36. fi
    37.  
    38. echo '----------------------------------------------'
    39. echo ''
    40.  
    41. done

    再利用 ccpp0@DRL 写的执行脚本,就可以把网通/电信等IP列表写出路由表中

    1. #!/bin/sh
    2. #write By ccpp0
    3.  
    4. DEFAULTGW=`/usr/bin/grep defaultrouter /etc/rc.conf | /usr/bin/sed "s/[^0-9\.]//g"`
    5. #CNCGW=60.28.32.49
    6. #CNCIP=/root/cn_isp/IP_CNC
    7. CHINANETGW=221.239.1.193
    8. CHINANETIP=/root/cn_isp/IP_CHINANET
    9.  
    10. /sbin/route flush
    11. /sbin/route add default ${DEFAULTGW}
    12. #for RL in `/bin/cat ${CNCIP}`; do
    13. #        /sbin/route add -net ${RL} ${CNCGW}
    14. #done
    15.  
    16. for RL in `/bin/cat ${CHINANETIP}`; do
    17.         /sbin/route add -net ${RL} ${CHINANETGW}
    18. done

    Update:
    稍微修正一下,没有必要把所有的网通/电信网段都加进路由表

  • 相关阅读:
    AX7 VM can not starting
    AX3空Invoice明细问题
    Solution to “VirtualBox can't operate in VMX root mode” error in Windows 7
    Inventory of the materials to teach you how to query a date certain combination of dimensions
    How to Debug Enterprise Portal Code in Dynamics AX 2009
    Axapta 3 COM Connector
    AX 与Citrix打印机问题
    AX ERP 真正的自动批处理
    SQL语句转摘
    D365: Table, Form, Class to extension
  • 原文地址:https://www.cnblogs.com/studio313/p/985719.html
Copyright © 2020-2023  润新知