Skip to content

Instantly share code, notes, and snippets.

@lsylsy2
Last active August 23, 2018 00:17
Show Gist options
  • Save lsylsy2/d5d5ee1b48ff64921529 to your computer and use it in GitHub Desktop.
Save lsylsy2/d5d5ee1b48ff64921529 to your computer and use it in GitHub Desktop.
从APNIC下载中国IP,并挑出免费地址
#!/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
@lsylsy2
Copy link
Author

lsylsy2 commented Jun 2, 2015

特殊处理了下162.105段,还没来得及测试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment