vpngate_scrapper.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. import os
  3. import csv
  4. import urllib.request
  5. import base64
  6. import datetime
  7. serversnum = 50
  8. 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" ]
  9. reqpart = "/api/iphone/"
  10. # listurl = "http://www.vpngate.net/api/iphone/"
  11. ovpndirdir = "~/docs/ovpn"
  12. ovpnpath = "/tmp/profile.ovpn"
  13. fmtstrhead = "{:^4} | {:^4} | {:^4} | {:^30} | {:^10}"
  14. fmtstr = "[{:>2}] | {} | {:>4} | {:<30} | {:^10}"
  15. scriptdir = os.path.expanduser("~/.config/openvpn")
  16. def save_ovpn_file(reader, index, path):
  17. current = reader.__next__()
  18. fpath = "%s/[#%02d]_[%s][P%03d]_%s.ovpn" % (path, index, current[6], int(current[3]), current[0])
  19. with open(fpath, 'w') as f:
  20. # with open("%s/[#%d][P%s path + "/[#" + str(index) + "][P:" + current[0] + ".ovpn", 'w') as f:
  21. f.write(base64.b64decode(current[14]).decode('ascii'))
  22. f.write( "script-security 2\n" )
  23. f.write( "up \"" + scriptdir + "/up.sh\"\n" )
  24. f.write( "down \"" + scriptdir + "/down.sh\"\n" )
  25. f.write( "data-ciphers 'AES-128-CBC:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305'\n" )
  26. ## Mirror selection
  27. # fmtmirr = "[{:3}] | {:>40}"
  28. # for i in range(len(mirrorlist)):
  29. # print(fmtmirr.format( i, mirrorlist[i] ))
  30. mirchoice = 0
  31. # while mirchoice < 0 or mirchoice > (len(mirrorlist) - 1):
  32. # mirchoice = int(input("Select a mirror:: "))
  33. listurl = mirrorlist[mirchoice] + reqpart
  34. response = urllib.request.urlopen(listurl).read().decode('utf-8').split('\n')
  35. reader = csv.reader(response, delimiter=',')
  36. # Get rid of irrelevant headers
  37. reader.__next__()
  38. reader.__next__()
  39. dirpath = os.path.expanduser(ovpndirdir) + "/" + datetime.datetime.now().strftime("%Y-%m-%d_%H_%M")
  40. if not os.path.exists(dirpath):
  41. os.makedirs(dirpath)
  42. for i in range(serversnum):
  43. save_ovpn_file(reader, i, dirpath)
  44. #print(fmtstrhead.format( "INDX", "LCTN", "Ping", "Server ID", "Score" ))
  45. #for i in range(serversnum):
  46. # current = reader.__next__()
  47. # print(fmtstr.format( i, current[6], current[3], current[0], current[2] ))
  48. # profiles.append(current[14])