chanlang
wget使用大写的O
慕仔7147015
# 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
Longingforthesun
不是很懂,这应该不是shell的语法吧