-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScanFreess.py
83 lines (69 loc) · 2.23 KB
/
ScanFreess.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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import base64
import os
import requests
import json
from subprocess import call, Popen
import platform
osStr = platform.system()
if osStr == "Linux":
configPath = "/home/shura/Softs/shadowsocks.json"
else:
configPath = "D:\Soft\Shadowsocks\gui-config.json"
ssClientPath = "D:\Soft\Shadowsocks\Shadowsocks.exe"
def deCode():
count = 0
# TODO 本地解析二维码
# 在线解析二维码接口不稳定,粗暴的重复请求来解决
while True:
count += 1
r = requests.post('https://cli.im/Api/Browser/deqr', data={'data': 'http://freess.org/images/servers/jp02.png'})
res = r.json()
if res["status"] == 1 and count < 10: # 最多请求十次
return res
def fetchSSInfo():
res = deCode()
rawData = res['data']['RawData'][5:]
ss = base64.b64decode(rawData).decode()
subss = str(ss).split(':')
mod = subss[0]
pwd = str(ss).split(':')[1].split('@')[0]
ip = str(ss).split(':')[1].split('@')[1]
port = subss[2].strip()
list = [ip, port, pwd, mod]
return list
def modifyConfigJson():
ssInfo = fetchSSInfo()
# 读取配置文件
with open(configPath, 'r') as f:
ssConfig = json.load(f)
# TODO 自动添加freess而不只是修改
if osStr == "Linux":
ssConfig['server'] = ssInfo[0]
ssConfig['server_port'] = ssInfo[1]
ssConfig['password'] = ssInfo[2]
ssConfig['method'] = ssInfo[3]
else:
ssConfigList = ssConfig["configs"]
for data in ssConfigList:
if data['remarks'] == "freess":
data['server'] = ssInfo[0]
data['server_port'] = ssInfo[1]
data['password'] = ssInfo[2]
data['method'] = ssInfo[3]
break
with open(configPath, 'w') as f:
json.dump(ssConfig, f, indent=2)
def restartSSClient():
if osStr == "Linux":
os.system('ps -C sslocal -o pid=|xargs kill -9')
Popen('sslocal -c /home/shura/Softs/shadowsocks.json', shell=True)
else:
os.system('taskkill /f /im Shadowsocks.exe')
Popen(ssClientPath)
def main():
modifyConfigJson()
restartSSClient()
if __name__ == "__main__":
main()