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

For Python3.5 #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 14 additions & 13 deletions chnroutes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

import re
import urllib2
import urllib.request
import sys
import argparse
import math
Expand All @@ -15,8 +15,8 @@ def generate_ovpn(metric):
route_item="route %s %s net_gateway %d\n"%(ip,mask,metric)
rfile.write(route_item)
rfile.close()
print "Usage: Append the content of the newly created routes.txt to your openvpn config file," \
" and also add 'max-routes %d', which takes a line, to the head of the file." % (len(results)+20)
print ("Usage: Append the content of the newly created routes.txt to your openvpn config file," \
" and also add 'max-routes %d', which takes a line, to the head of the file." % (len(results)+20))


def generate_linux(metric):
Expand Down Expand Up @@ -60,8 +60,8 @@ def generate_linux(metric):
downfile.write('rm /tmp/vpn_oldgw\n')


print "For pptp only, please copy the file ip-pre-up to the folder/etc/ppp," \
"and copy the file ip-down to the folder /etc/ppp/ip-down.d."
print ("For pptp only, please copy the file ip-pre-up to the folder/etc/ppp," \
"and copy the file ip-down to the folder /etc/ppp/ip-down.d.")

def generate_mac(metric):
results=fetch_ip_data()
Expand Down Expand Up @@ -114,8 +114,8 @@ def generate_mac(metric):
upfile.close()
downfile.close()

print "For pptp on mac only, please copy ip-up and ip-down to the /etc/ppp folder," \
"don't forget to make them executable with the chmod command."
print ("For pptp on mac only, please copy ip-up and ip-down to the /etc/ppp folder," \
"don't forget to make them executable with the chmod command.")

def generate_win(metric):
results = fetch_ip_data()
Expand Down Expand Up @@ -149,8 +149,8 @@ def generate_win(metric):
# down_vbs_wrapper.write('Set objShell = CreateObject("Wscript.shell")\ncall objShell.Run("vpndown.bat",0,FALSE)')
# down_vbs_wrapper.close()

print "For pptp on windows only, run vpnup.bat before dialing to vpn," \
"and run vpndown.bat after disconnected from the vpn."
print ("For pptp on windows only, run vpnup.bat before dialing to vpn," \
"and run vpndown.bat after disconnected from the vpn.")

def generate_android(metric):
results = fetch_ip_data()
Expand Down Expand Up @@ -187,15 +187,16 @@ def generate_android(metric):
upfile.close()
downfile.close()

print "Old school way to call up/down script from openvpn client. " \
"use the regular openvpn 2.1 method to add routes if it's possible"
print ("Old school way to call up/down script from openvpn client. " \
"use the regular openvpn 2.1 method to add routes if it's possible")


def fetch_ip_data():
#fetch data from apnic
print "Fetching data from apnic.net, it might take a few minutes, please wait..."
print ("Fetching data from apnic.net, it might take a few minutes, please wait...")
url=r'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest'
data=urllib2.urlopen(url).read()
data=urllib.request.urlopen(url).read()
data=data.decode('UTF-8')

cnregex=re.compile(r'apnic\|cn\|ipv4\|[0-9\.]+\|[0-9]+\|[0-9]+\|a.*',re.IGNORECASE)
cndata=cnregex.findall(data)
Expand Down