Skip to content

Instantly share code, notes, and snippets.

@codexss
Created May 25, 2016 05:41
Show Gist options
  • Save codexss/63bdcead19f0cf58874a8c588cef580e to your computer and use it in GitHub Desktop.
Save codexss/63bdcead19f0cf58874a8c588cef580e to your computer and use it in GitHub Desktop.
#!/bin/sh
server_IP=12.34.56.78
curl 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > chnroute.txt
iptables -t nat -N SHADOWSOCKS >/dev/null 2>&1 &
iptables -t nat -A SHADOWSOCKS -d $server_IP -j RETURN
iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN
ipset flush
ipset create chnroute hash:net >/dev/null 2>&1 &
cat chnroute.txt | xargs -I ip ipset add chnroute ip
rm chnroute.txt
iptables -t nat -A SHADOWSOCKS -m set --match-set chnroute dst -j RETURN
iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 1080
iptables -t nat -D PREROUTING -p tcp -j SHADOWSOCKS >/dev/null 2>&1 &
iptables -t nat -D OUTPUT -p tcp -j SHADOWSOCKS >/dev/null 2>&1 &
iptables -t nat -A PREROUTING -p tcp -j SHADOWSOCKS
iptables -t nat -A OUTPUT -p tcp -j SHADOWSOCKS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment