XenoTheStrange

Scrape VPNGATE Openvpn Config Files Python]

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