-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscrap_vpns.py
executable file
·52 lines (48 loc) · 1.85 KB
/
scrap_vpns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import re
import base64
import urllib.request
import os, shutil
import socket
import time
# Create folder
vpn_dir = 'VPN'
if os.path.exists(vpn_dir):
shutil.rmtree(vpn_dir)
os.makedirs(vpn_dir)
# Create vpn's
url = 'http://www.vpngate.net/api/iphone/'
count = 0
response = urllib.request.urlopen(url)
for line in response:
line_decoded = line.decode('utf-8')
if( "owner" in line_decoded):
line_striped = re.sub("^vpn.*owner,,","",line_decoded).strip()
try:
# Decode line
ovpn_text = base64.b64decode(line_striped).decode("utf-8")
# Delete comments
ovpn_text = re.sub("(#|;).*\n","" ,ovpn_text)
title = str(count)+".ovpn"
ovpn_file = open(vpn_dir+"/"+title, 'w')
ovpn_file.write(ovpn_text)
ovpn_file.close()
count += 1
except:
pass
# Delete powered off servers
for filename in os.listdir(vpn_dir):
ovpn_file = open(vpn_dir+"/"+filename, 'r')
for line in ovpn_file.readlines():
if "remote" in line:
server = line.strip().split(" ")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
start = time.perf_counter()
result = sock.connect_ex((server[1],int(server[2])))
endtime = time.perf_counter()-start
if result == 0 and endtime < 0.5:
print("Server "+str(server[1])+":"+str(server[2])+" ON, Tiempo de respuesta: "+str(endtime))
else:
print("Server "+str(server[1])+":"+str(server[2])+" OFF, borrando")
os.remove(vpn_dir+"/"+filename)