Skip to content

Instantly share code, notes, and snippets.

@zengjie
Last active March 21, 2017 03:59
Show Gist options
  • Save zengjie/5325d76b881276b88dc735bf6de47f54 to your computer and use it in GitHub Desktop.
Save zengjie/5325d76b881276b88dc735bf6de47f54 to your computer and use it in GitHub Desktop.
Update ChinaDNS IP Address File
if curl -f 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' -o /tmp/chinaip.list; then
cat /tmp/chinaip.list | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /tmp/chinadns_chnroute.txt
if [[ $(wc -l </tmp/chinadns_chnroute.txt) -ge 100 ]]; then
echo '47.89.44.170/32' >> /tmp/chinadns_chnroute.txt
echo '139.162.86.215/32' >> /tmp/chinadns_chnroute.txt
cp /tmp/chinadns_chnroute.txt /etc/chinadns_chnroute.txt
else
echo 'Too few lines. File corrupted?'
fi;
else
echo 'Failed to download China IP addresses'
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment