XenoTheStrange

[Python] Get All VPNGATE Openvpn Config Files

Jan 1st, 2022 (edited)
258
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import requests
  3. from base64 import b64decode
  4. import os
  5.  
  6. debug = False
  7. sort_by = "score"
  8. #sort by score, speed, hostname, whatever rly.
  9.  
  10. def get_csv():
  11.     #download and save the csv file
  12.     print("[INFO] Fetching csv file...")
  13.     tmp = requests.get("http://www.vpngate.net/api/iphone/")
  14.     csv = open("vpngate.proixes.csv", "w")
  15.     csv.write(tmp.text)
  16.     csv.close()
  17.  
  18. try:
  19.     open("vpngate.proixes.csv", "r")
  20.     print("[INFO] vpngate.proxies.csv exists. Using that.\n    Delete to fetch new version.")
  21. except FileNotFoundError:
  22.         get_csv()
  23.  
  24. print(f"[INFO] Sorting by {sort_by}...")
  25. csv = open("vpngate.proixes.csv", "r").read().split("\n")[1:-2]
  26. legend = [i.lower() for i in csv.pop(0)[1:].split(",")]
  27.  
  28. #dict from csv. Fields in legend
  29. csv_dict = [dict(zip(legend, csv[i].split(","))) for i in range(1,len(csv))]
  30. dict_sorted = sorted(csv_dict, key=lambda d: d[sort_by])
  31.  
  32.  
  33. print("[INFO] Writing files")
  34. try:
  35.     os.mkdir("opvpn files")
  36. except:
  37.     if debug:
  38.         print("[Debug] opvpn files directory already exists")
  39. os.chdir("opvpn files")
  40. for i, li in enumerate(dict_sorted):
  41.     name = f"{i}-{li['countryshort']}_{li['hostname']}_{li['ip']}.ovpn"
  42.     file = open(name, "w")
  43.     file.write(b64decode(li['openvpn_configdata_base64']).decode("utf-8"))
  44.     file.close()
  45.  
  46. print("done")
  47.  
Comments
Add Comment
Please, Sign In to add comment