#
!/bin/sh
FILE =/ usr / home / haoyu / ip_apnic
rm - f $FILE
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 - 1
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 - h whois . apnic . net $ip | sed - e ' /./{H;$!d;} ' - e ' x;/netnum/!d ' | grep ^ netname | sed - e ' s/.*: (.*)//1/g ' | sed - e ' s/-.*//g ' `
case $NETNAME in
CHINANET | CNCGROUP)
echo $ip / $mask >> $NETNAME
;;
CHINATELECOM)
echo $ip / $mask >> $NETNAME
;;
OTHER_NETNAME_here)
;;
esac
done
FILE =/ usr / home / haoyu / ip_apnic
rm - f $FILE
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 - 1
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 - h whois . apnic . net $ip | sed - e ' /./{H;$!d;} ' - e ' x;/netnum/!d ' | grep ^ netname | sed - e ' s/.*: (.*)//1/g ' | sed - e ' s/-.*//g ' `
case $NETNAME in
CHINANET | CNCGROUP)
echo $ip / $mask >> $NETNAME
;;
CHINATELECOM)
echo $ip / $mask >> $NETNAME
;;
OTHER_NETNAME_here)
;;
esac
done