Last active
August 23, 2018 00:17
-
-
Save lsylsy2/d5d5ee1b48ff64921529 to your computer and use it in GitHub Desktop.
从APNIC下载中国IP,并挑出免费地址
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Downloading IP list from APNIC...." | |
apniclist=`wget -q -O- http://ftp.apnic.net/stats/apnic/delegated-apnic-latest |grep "apnic|CN|ipv4|"` | |
echo "Checking blocks..." | |
rm cidr.txt | |
for ipblock in ${apniclist[@]} | |
do | |
ip=`echo $ipblock | cut -d "|" -f4` | |
block=`echo $ipblock | cut -d "|" -f5` | |
testtrace=`traceroute -n -m 10 -w 1 $ip |awk 'NR>1{print $2}'|grep "162.105.252."` | |
if [[ $testtrace == *"162.105.252."* ]] | |
then | |
block_cidr=`printf "%.0f\n" $(echo "32-l($block)/l(2)" |bc -l)` | |
echo "block:$ip/$block_cidr available" | |
echo "$ip/$block_cidr" >>cidr.txt | |
else | |
echo "block:$ip/$block_cidr unavailable" | |
fi | |
if [[ $ip == *"162.105."* ]] | |
then | |
echo "special block:$ip/$block_cidr available" | |
echo "$ip/$block_cidr" >>cidr.txt | |
continue | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
特殊处理了下162.105段,还没来得及测试