慕仔7147015
2018-05-25 17:05
Jeson老师 Download_ip_pools.sh 我一份吗 我的邮箱xiaoqing7701@126.com
# 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 $ip@whois.apnic.net | grep -i ".*chinanet.*\|.*telecom.*" >/dev/null;then
echo $ip/$mask>>chinanet
elif whois $ip@whois.apnic.net | grep -i ".*unicom.*" >>/dev/null ;then
echo $ip/$mask>>unicom
elif whois $ip@whois.apnic.net | grep -i ".*chinamobile.*" >>/dev/null ;then
echo $ip/$mask>>cmcc
else
echo $ip/$mask>> others
fi
done
Linux 智能DNS
13499 学习 · 7 问题
相似问题
回答 4