歡迎您光臨本站 註冊首頁

[shell] 配置智能DNS時獲取各運營商IP段

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

[shell] 配置智能DNS時獲取各運營商IP段

配置智能DNS時獲取各運營商IP段




原文請訪問:http://m114.org
APNIC是管理亞太地區IP地址分配的機構,它有著豐富準確的IP地址分配庫,同時這些信息也是對外公開的!

在Linux下獲得一些國內運營商的IP地址段的情況:



1、編譯安裝軟體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 && make install複製代碼
2、獲取IP並轉換為智能DNS格式#!/bin/bash

•# date:          2011-10-28

•# Author: vinson

•# Blog:          http://m114.org



•#獲取網通IP

•whois3 -h whois.apnic.net -l -i mb MAINT-CNCGROUP |grep "descr" |grep "Reverse" | awk -F "for" '{if($2!="") print$2}' |sort -n | awk 'BEGIN{print "acl \"CNC\" '{'"}{print $1";"}END{print "'}';"}' > cnc_acl.conf



•#獲取電信IP

•whois3 -h whois.apnic.net -l -i mb MAINT-CHINANET |grep "descr" |grep "Reverse" | awk -F "for" '{if($2!="") print$2}' |sort -n | awk 'BEGIN{print "acl \"CTC\" '{'"}{print $1";"}END{print "'}';"}' > ctc_acl.conf



•#獲取鐵通IP

•whois3 -h whois.apnic.net -l -i mb MAINT-CN-CRTC |grep "inetnum" |sed 's/inetnum: //g' |sort -n |



•awk -F'[.-]' '

•{

•        print $1"."$2"."$3"."$4,(255-($(NF-3)-$1))"."(255-($(NF-2)-$2))"."(255-($(NF-1)-$3))"."(255-($NF-$4))

•}' |



•while read ip mask

•do

•        a=$(ipcalc -p $ip $mask |awk -F= '{print$2}')

•        echo $ip/$a >>temp

•done

•more temp |awk 'BEGIN{print "acl \"CRTC\" '{'"}{print $1";"}END{print "'}';"}' > crtc_acl.conf

•rm -f temp複製代碼
下載:
腳本http://www.kuaipan.cn/index.php?ac=file&oid=5920767036360052
電信http://www.kuaipan.cn/index.php?ac=file&oid=5920767036360052
網通http://www.kuaipan.cn/index.php?ac=file&oid=5920767036360055
鐵通http://www.kuaipan.cn/index.php?ac=file&oid=5920767036360053

參考:
http://blog.csdn.net/east271536394/article/details/6402475
http://hi.baidu.com/leejun_2005/blog/item/5ff74c3fa4b2f22971cf6cd5.html
http://hi.baidu.com/dmkj2008/blog/item/98a23850ae939d531038c28b.html

[火星人 ] [shell] 配置智能DNS時獲取各運營商IP段已經有318次圍觀

http://coctec.com/docs/service/show-post-1812.html