Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux: system wide static /etc/network/routes #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ route-delay 2
另外, 这里假定了你的android已经安装过busybox, 否则请先安装busybox再进行以上操作, 还需要知道的是, 这个脚本在手机上执行会花费比较长的时间, 如非必要, 就不要用了. 也许采用非redirect-gateway方式, 然后在ovpn配置文件里添加几条需要路由的ip段是比较快捷方便的做法.
基于Linux的第三方系统的路由器

一些基于Linux系统的第三方路由器系统如: OpenWRT, DD-WRT, Tomato 都带有VPN(PPTP/Openvpn)客户端的, 也就是说, 我们只需要在路由器进行VPN拨号, 并利用本项目提供的路由表脚本就可以把VPN针对性翻墙扩展到整个局域网. 当然, 使用这个方式也是会带来副作用, 即局域网的任何机器都不适合使用Emule或者BT等P2P下载软件. 但对于那些不使用P2P, 希望在路由器上设置针对性翻墙的用户, 这方法十分有用, 因为只需要一个VPN帐号, 局域网内的所有机器, 包括使用wifi的手机都能自动翻墙. 相信配置方式请参考: Autoddvpn 项目.
一些基于Linux系统的第三方路由器系统如: OpenWRT, DD-WRT, Tomato 都带有VPN(PPTP/Openvpn)客户端的, 也就是说, 我们只需要在路由器进行VPN拨号, 并利用本项目提供的路由表脚本就可以把VPN针对性路由扩展到整个局域网. 当然, 使用这个方式也是会带来副作用, 即局域网的任何机器都不适合使用Emule或者BT等P2P下载软件. 但对于那些不使用P2P, 希望在路由器上设置针对性路由的用户, 这方法十分有用, 因为只需要一个VPN帐号, 局域网内的所有机器, 包括使用wifi的手机都能自动路由. 相信配置方式请参考: Autoddvpn 项目.

## 信息反馈

Expand Down
14 changes: 14 additions & 0 deletions chnroutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ def generate_ovpn(metric):
" and also add 'max-routes %d', which takes a line, to the head of the file." % (len(results)+20)


def generate_routes(iface):
results = fetch_ip_data()
rfile=open('routes','w')
for ip,mask,_ in results:
route_item="%s %s %s\n"%(ip,mask,iface)
rfile.write(route_item)
rfile.close()
print "Usage: Append the content of the newly created routes to /etc/network/routes," \
" total routes %d" % (len(results)+20)


def generate_linux(metric):
results = fetch_ip_data()
upscript_header=textwrap.dedent("""\
Expand Down Expand Up @@ -195,6 +206,7 @@ def fetch_ip_data():
#fetch data from apnic
print "Fetching data from apnic.net, it might take a few minutes, please wait..."
url=r'https://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest'
# url=r'http://192.168.1.254/delegated-apnic-latest'
data=urllib2.urlopen(url).read()

cnregex=re.compile(r'apnic\|cn\|ipv4\|[0-9\.]+\|[0-9]+\|[0-9]+\|a.*',re.IGNORECASE)
Expand Down Expand Up @@ -247,6 +259,8 @@ def fetch_ip_data():

if args.platform.lower() == 'openvpn':
generate_ovpn(args.metric)
elif args.platform.lower() == 'routes':
generate_routes('___Interface___')
elif args.platform.lower() == 'linux':
generate_linux(args.metric)
elif args.platform.lower() == 'mac' or args.platform.lower() == 'darwin':
Expand Down