vpngate.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. import os
  3. import csv
  4. import urllib.request
  5. import base64
  6. serversnum = 30
  7. profiles = []
  8. choice = -1
  9. mirrorlist = [ "https://www.vpngate.net", "http://5.181.235.14:29916", "http://88.218.17.24:20261", "http://138.199.46.86:36667", "http://109.111.243.206:17579", "http://78.142.193.246:33304", "http://163.182.174.159:18358", "http://91.193.75.5:45082", "http://103.201.129.226:14684", "http://146.70.205.2:6283", "http://146.70.205.6:34299", "http://62.133.35.246:2265" ]
  10. reqpart = "/api/iphone/"
  11. # listurl = "http://www.vpngate.net/api/iphone/"
  12. ovpnpath = "/tmp/profile.ovpn"
  13. fmtstrhead = "{:^4} | {:^4} | {:^4} | {:^30} | {:^10}"
  14. fmtstr = "[{:>2}] | {} | {:>4} | {:<30} | {:^10}"
  15. ## Mirror selection
  16. mirchoice = -1
  17. fmtmirr = "[{:3}] | {:>40}"
  18. for i in range(len(mirrorlist)):
  19. print(fmtmirr.format( i, mirrorlist[i] ))
  20. while mirchoice < 0 or mirchoice > (len(mirrorlist) - 1):
  21. mirchoice = int(input("Select a mirror:: "))
  22. listurl = mirrorlist[mirchoice] + reqpart
  23. response = urllib.request.urlopen(listurl).read().decode('utf-8').split('\n')
  24. reader = csv.reader(response, delimiter=',')
  25. # Get rid of irrelevant headers
  26. reader.__next__()
  27. reader.__next__()
  28. print(fmtstrhead.format( "INDX", "LCTN", "Ping", "Server ID", "Score" ))
  29. for i in range(serversnum):
  30. current = reader.__next__()
  31. print(fmtstr.format( i, current[6], current[3], current[0], current[2] ))
  32. profiles.append(current[14])
  33. while choice < 0 or choice > serversnum:
  34. choice = int(input("Choose a profile: "))
  35. scriptdir = os.path.expanduser("~/.config/openvpn")
  36. with open(ovpnpath, 'w') as f:
  37. f.write(base64.b64decode(profiles[choice]).decode('ascii'))
  38. f.write( "script-security 2\n" )
  39. f.write( "up \"" + scriptdir + "/up.sh\"\n" )
  40. f.write( "down \"" + scriptdir + "/down.sh\"\n" )
  41. f.write( "data-ciphers 'AES-128-CBC:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305'\n" )
  42. # os.system( "sudo openvpn " + runopts + "--config" + ovpnpath )
  43. os.system( "sudo openvpn " + ovpnpath )