課程
/運維&測試
/Linux
/Linux 智能DNS
Jeson老師 ?Download_ip_pools.sh 我一份嗎 我的郵箱[email protected]
2018-05-25
源自:Linux 智能DNS 2-6
正在回答
#?script?for?getting?smart?dns?IP?database FILE=/opt/apnic/ip_apnic if?[?!?-e?$FILE?];then ??wget?http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest?-O?$FILE fi rm?-f?cn.net?chinanet?unicom?cmcc?others grep?'apnic|CN|ipv4|'?$FILE?|?cut?-f4,5?-d?'|'?|sed?-e?'s/|/?/g'?|?while?read?ip?cnt do ????echo?$ip:$cnt ????mask=$(cat?<<?EOF?|?bc?|?tail?-1?? ??????pow=32;?? ??????define?log2(x)?{???? ????????if?(x?<=?1)?return?(pow); ????????pow--; ????????return?(log2(x/2)); ??????} ??????log2($cnt) ????EOF ????) ????echo?$ip/$mask>>?cn.net ????if?whois?$ip?|?grep?"netname"?|?grep?-i?".*chinanet.*\|.*telecom.*"?>?/dev/null;then ??????echo?$ip/$mask>>?chinanet ????elif?whois?$ip?|?grep?"netname"?|?grep?-i?".*unicom.*"?>>?/dev/null;then ??????echo?$ip/$mask>>?unicom ????elif?whois?$ip?|?grep?"netname"?|?grep?-i?".*chinamobile.*"?>>?/dev/null;then ??????echo?$ip/$mask>>?cmcc ????else ??????echo?$ip/$mask>>?others ????fi done
腳本都是錯誤的
#!/bin/bash
FILE=/opt/apnic/ip_apnic
rm -f $FILE
wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-extended-20180603 -O $FILE
grep 'apnic|CN|ipv4|' $FILE | cut -f4,5 -d '|' |sed -e 's/|/ /g' | while read ip cnt
do
echo $ip:$cnt
mask=$(cat << EOF | bc | tail -1
? ? ? ? pow=32;
? ? ? ? define log2(x){
? ? ? ? if(x<=1)return(pow);
? ? ? ? pow--;
? ? ? ? return(log2(x/2));
? ? ? ? }
? ? ? ? log2($cnt)
EOF
)
echo $ip/$mask >>cn.net
if whois [email protected] | grep -i ".*chinanet.*\|.*telecom.*" >/dev/null;then
? ? ? ? echo $ip/$mask>>chinanet
elif ?whois [email protected] | grep ?-i ".*unicom.*" >>/dev/null ;then
? ? ? ? echo $ip/$mask>>unicom
elif ?whois [email protected] | grep ?-i ".*chinamobile.*" >>/dev/null ;then
echo $ip/$mask>>cmcc
else
? ? ? ? echo $ip/$mask>> others
fi
done
舉報
DNS學習進階教程,智能DNS實現與安全,講解常見攻擊原理和預防手段
4 回答主機在線檢測
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2022-08-05
2018-08-08
腳本都是錯誤的
2018-06-03
#!/bin/bash
FILE=/opt/apnic/ip_apnic
rm -f $FILE
wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-extended-20180603 -O $FILE
grep 'apnic|CN|ipv4|' $FILE | cut -f4,5 -d '|' |sed -e 's/|/ /g' | while read ip cnt
do
echo $ip:$cnt
mask=$(cat << EOF | bc | tail -1
? ? ? ? pow=32;
? ? ? ? define log2(x){
? ? ? ? if(x<=1)return(pow);
? ? ? ? pow--;
? ? ? ? return(log2(x/2));
? ? ? ? }
? ? ? ? log2($cnt)
EOF
)
echo $ip/$mask >>cn.net
if whois [email protected] | grep -i ".*chinanet.*\|.*telecom.*" >/dev/null;then
? ? ? ? echo $ip/$mask>>chinanet
elif ?whois [email protected] | grep ?-i ".*unicom.*" >>/dev/null ;then
? ? ? ? echo $ip/$mask>>unicom
elif ?whois [email protected] | grep ?-i ".*chinamobile.*" >>/dev/null ;then
echo $ip/$mask>>cmcc
else
? ? ? ? echo $ip/$mask>> others
fi
done