#!/bin/sh FILE=/root/apnic/ip_apnic wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest -O $FILE grep 'apnic|CN|ipv4|' $FILE |cut -f 4,5 -d'|'|sed -e 's/|/ /g'| while read ip cnt do echo $ip:$cnt mask=$(cat << EOF |bc |tail -l pow=32; define log2(x) { if (x<=1) return (pow); pow--; return(log2(x/2)); } log2($cnt) EOF ) echo $ip/$mask>>cn.net NETNAME=`whois $ip@whois.apnic.net | grep ^netname |awk '{print $2}'| awk -F- '{print $1}' ` case $NETNAME in CHINANET ) echo $ip/$mask>> ChinaNet ;; Chinaunicom | UNICOM ) echo $ip/$mask>> UNICOM ;; *) echo $ip/$mask>> OTHER ;; esac done