Last active
December 27, 2015 17:59
-
-
Save maliubiao/7366379 to your computer and use it in GitHub Desktop.
enable-routing.py
This file contains hidden or 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
| import subprocess | |
| import os | |
| if __name__ != "__main__": | |
| exit(0) | |
| #local socks proxy address | |
| _SOCKS_SERVER = "127.0.0.1:###" | |
| #remote server address | |
| _SERVER = "106.###.###.###" | |
| #local gateway | |
| _GATEWAY = "########" | |
| #local dns | |
| _DNS = "114.114.114.114" | |
| #router addr | |
| _ROUTER = "10.0.0.2" | |
| #router netmask | |
| _NETMASK = "255.255.255.0" | |
| #tun2socks location | |
| _tun2socks = "pathto/tun2socks/badvpn-tun2socks" | |
| _call = subprocess.call | |
| print """\ | |
| ################# | |
| setup router | |
| ################# | |
| """ | |
| import getpass | |
| _user = getpass.getuser() | |
| _call("ip tuntap add dev tun0 mode tun user %s" % (_user), shell=True) | |
| _call("ifconfig tun0 %s netmask %s" % (_ROUTER, _NETMASK), shell = True) | |
| print """\ | |
| ################## | |
| enable tun2socks | |
| ################## | |
| """ | |
| status = os.fork() | |
| if status == 0: | |
| os.execvp(_tun2socks, ["tun2socks", | |
| "--tundev", "tun0", | |
| "--netif-ipaddr", _ROUTER, | |
| "--netif-netmask", _NETMASK, | |
| "--socks-server-addr", _SOCKS_SERVER | |
| ]) | |
| exit(0) | |
| print """\ | |
| #################### | |
| set routing table | |
| #################### | |
| """ | |
| _call("route add %s gw %s metric 5" % (_SERVER, _GATEWAY), shell=True) | |
| _call("route add %s gw %s metric 5" % (_DNS, _GATEWAY), shell=True) | |
| _call("route del default", shell=True) | |
| _call("route add default gw %s metric 6" % (_ROUTER), shell=True) | |
| _call("route add default gw %s metric 7" % (_GATEWAY), shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment