从apnic提取ip信息脚本分享
#!/bin/bash
# download from apnic
rm -f delegated-apnic-latest
wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest
# ips allocated to china.
grep 'apnic|cn|ipv4|' delegated-apnic-latest | cut -f 4 -d'|' > delegated-apnic-cn
# get detail of echo ip from apnic database.
rm -f apnic_cn.txt
while read ip
do
# query apnic database
echo "query who is $ip"
whois -h whois.apnic.net $ip > tmp.txt
grep inetnum tmp.txt >> apnic_cn.txt # ip range
grep netname tmp.txt >> apnic_cn.txt # netname which include sp information
grep descr tmp.txt >> apnic_cn.txt # description which include province information
echo "" >> apnic_cn.txt
done < delegated-apnic-cn
# clean up
rm -f tmp.txt
rm -f delegated-apnic-latest
rm -f delegated-apnic-cn