收集IP地址

wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest

grep 'apnic|CN|ipv4' delegated-apnic-latest | cut -d '|' -f 4,5 | sed -e 's/|/ /g' >/tmp/ip_apnic

#!/bin/bash

classify() {
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 $pow
echo $ip/$mask
#echo $ip/$mask >> cn.net
NETNAME=`whois [email protected] | sed -e '/./{H;$!d;}' -e 'x;/netnum/!d' | grep ^netname | awk '{print $2}' | awk -F- '{print$1}'`
        case $NETNAME in CHINANET|CHINATELECOM)
                echo $ip/$mask TELECOM
                echo "**********"
                #echo $ip/$mask  >> TELECOM
        ;;
        *)
                echo $ip/$mask OTHER
                echo "**********"
                #echo $ip/$mask >> OTHER
        ;;
        esac
sleep 2
done < /tmp/ip_apnic
}

本文出自 “开源一员” 博客,谢绝转载!

你可能感兴趣的:(return,IP,mask,IP地址)