-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
125 lines (109 loc) · 3.79 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from subprocess import check_output
from requests import Session
from json import loads
from time import time as ttime, sleep
from hashlib import md5
USER = ""
PSW = ""
BASE_URL = "https://api.staticnetcontent.com"
WG_PORT = 443
reqSess = Session()
#reqSess.verify = False
reqSess.headers.update({"Content-Type": "application/x-www-form-urlencoded", "User-Agent": "okhttp/4.9.3"})
def genWireKey():
privKey = check_output("wg genkey").decode().strip()
pubKey = check_output("wg pubkey", input=privKey.encode()).decode().strip()
return privKey, pubKey
def genClAuth():
time = int(ttime())
hash = md5("952b4412f002315aa50751032fcaab03{}".format(time).encode()).hexdigest()
return time, hash
def Login(user, psw):
time, hash = genClAuth()
data = {
"platform": "android",
"app_version": "3.1.887",
"client_auth_hash": hash,
"session_type_id": "4",
"time": time,
"username": user,
"password": psw
}
reqLogin = reqSess.post("{}/Session".format(BASE_URL), data=data)
LoginData = loads(reqLogin.text)['data']
return LoginData['session_auth_hash'], LoginData['is_premium']
def getServers(isPremium, type="wg"):
Servers = []
time, hash = genClAuth()
reqServers = reqSess.get("https://assets.staticnetcontent.com/serverlist/mob-v2/{}/{}".format(isPremium, hash))
jsonServers = loads(reqServers.text)['data']
for server in jsonServers:
country = {'name': server['short_name'], 'city': []}
for loc in server['groups']:
hosts = []
try:
nodes = loc['nodes']
except KeyError:
continue
for node in nodes:
if type == "wg":
hosts.append(node['ip3'])
else:
hosts.append(node['hostname'])
country['city'].append({'name': '{}-{}'.format(loc['city'], loc['nick']), "pubkey": loc['wg_pubkey'], 'host': hosts})
if not country['city'] == []:
Servers.append(country)
return Servers
def getPSK(accHash, pubKey):
time, hash = genClAuth()
data = {
"platform": "android",
"app_version": "3.1.887",
"client_auth_hash": hash,
"session_auth_hash": accHash,
"session_type_id": "4",
"time": time,
"wg_pubkey": pubKey,
"force_init": 1
}
reqPSK = reqSess.post("{}/WgConfigs/init".format(BASE_URL), data=data)
PSKData = loads(reqPSK.text)['data']
return PSKData['config']['PresharedKey']
def getWireIP(accHash, pubKey, HostName):
time, hash = genClAuth()
data = {
"platform": "android",
"app_version": "3.1.887",
"client_auth_hash": hash,
"session_auth_hash": accHash,
"session_type_id": "4",
"time": time,
"wg_pubkey": pubKey,
"hostname": HostName
}
reqIP = reqSess.post("{}/WgConfigs/connect".format(BASE_URL), data=data)
IPData = loads(reqIP.text)['data']['config']
return IPData['Address'], IPData['DNS']
accHash, isPremium = Login(USER, PSW)
servers = getServers(isPremium)
i = 0
num = len(servers)
privKey, pubKey = genWireKey()
psk = getPSK(accHash, pubKey)
for server in servers:
for city in server['city']:
ip, dns = getWireIP(accHash, pubKey, city['host'][0])
wgConfig = """[Interface]
PrivateKey = {privkey}
Address = {ip}
DNS = {dns}
[Peer]
PublicKey = {pubkey}
PresharedKey = {psk}
AllowedIPs = 0.0.0.0/0
Endpoint = {host}:{port}""".format(privkey=privKey, ip=ip, dns=dns, pubkey=city['pubkey'], psk=psk, host=city['host'][0], port=WG_PORT)
with open("./config/{}-{}.conf".format(server['name'], city['name']).replace(" ", "_"), "w") as conf:
conf.write(wgConfig)
sleep(1)
i += 1
print(f"\r{i}/{num}", flush=True, end="")