BG5 commited on
Commit
79bbd99
·
verified ·
1 Parent(s): e8afe9b

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +164 -0
main.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import atexit
2
+ import subprocess
3
+ from DrissionPage._configs.chromium_options import ChromiumOptions
4
+ from DrissionPage import Chromium
5
+ from DrissionPage._pages.web_page import WebPage
6
+ from urllib.parse import urlparse, parse_qs
7
+ from mitmproxy import http
8
+ from mitmproxy.tools.main import mitmdump
9
+ import os
10
+ import httpx
11
+ import json
12
+
13
+ try:
14
+ import time
15
+ except:
16
+ pass
17
+
18
+
19
+ def get_info():
20
+ # 获取当前代码运行的目录
21
+ current_directory = os.getcwd()
22
+ # 定义相对路径
23
+ relative_file_path = "2.html"
24
+ # 构建绝对路径
25
+ absolute_file_path = os.path.join(current_directory, relative_file_path)
26
+ print(absolute_file_path)
27
+ # 定义代理服务器地址
28
+ proxy_server = "http://127.0.0.1:12346"
29
+ co = ChromiumOptions().set_paths(browser_path=r"microsoft-edge")
30
+ co.incognito(on_off=True) # 无痕隐身模式打开的话。不会记住你的网站账号密码
31
+ co.headless(on_off=True)
32
+ co.set_local_port("12369")
33
+ # co.auto_port(on_off=True)
34
+ co.set_proxy(proxy_server)
35
+ # co.headless(on_off=True) # 或者使用 co.set_argument('--headless=new')
36
+ co.set_argument("--disable-gpu") # 禁用GPU加速
37
+ co.set_argument('--no-sandbox') # 禁用沙箱提高速度
38
+ co.set_argument('--disable-dev-shm-usage')
39
+ co.set_argument('--ignore-certificate-errors')
40
+ # co.set_argument('2>/dev/null')
41
+ co.set_user_agent(
42
+ user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTM, like Gecko) chrome/124.0.0.8 safari/537.36')
43
+ try:
44
+ browser2 = Chromium(chromium_options=co)
45
+ time.sleep(2)
46
+ browser2.get(absolute_file_path, retry=3, interval=2, timeout=15)
47
+ return browser2
48
+ except Exception as e:
49
+ print(f"打开主页失败,请检查网络连接,{e}")
50
+ return None
51
+ print(f"启动成功...")
52
+
53
+
54
+ def open_browser():
55
+ # 获取当前代码运行的目录
56
+ current_directory = os.getcwd()
57
+
58
+ # 定义相对路径
59
+ relative_file_path = "2.html"
60
+
61
+ # 构建绝对路径
62
+ absolute_file_path = os.path.join(current_directory, relative_file_path)
63
+ print(absolute_file_path)
64
+ # 定义代理服务器地址
65
+ proxy_server = "http://127.0.0.1:12346"
66
+ # 定义命令和路径
67
+ command = [
68
+ r"microsoft-edge",
69
+ # "--new-window",
70
+ "--headless",
71
+ "--no-sandbox",
72
+ "--disable-gpu",
73
+ "--remote-debugging-port=9222",
74
+ "--disable-dev-shm-usage",
75
+ "--ignore-certificate-errors",
76
+ "2>/dev/null",
77
+ f"--proxy-server={proxy_server}",
78
+ f"file:///{absolute_file_path}"
79
+ ]
80
+
81
+ # 启动 Microsoft Edge 浏览器并打开本地文件
82
+ try:
83
+ process = subprocess.Popen(command)
84
+
85
+ except Exception as e:
86
+ # print("Failed to start browser:", e)
87
+ process = None
88
+ return process
89
+
90
+
91
+ class ListenComment:
92
+ def __init__(self):
93
+
94
+ pass
95
+
96
+ # 定义一个函数,用于处理每一个响应
97
+ def request(self, flow: http.HTTPFlow) -> None:
98
+ if 'speech.platform.bing.com' in flow.request.pretty_url:
99
+ try:
100
+ flow.kill()
101
+ except Exception as e:
102
+ print(e)
103
+ # 解析 URL
104
+ url = flow.request.pretty_url
105
+ parsed_url = urlparse(url)
106
+ # 获取当前的UTC时间戳
107
+ utc_time = time.time()
108
+
109
+ # 将UTC时间戳转换为北京时间(东8区)的时间戳
110
+ beijing_time = utc_time + 8 * 3600 # 加上8小时的时间差
111
+
112
+ # 将北京时间的时间戳转换为结构化时间
113
+ beijing_struct_time = time.localtime(beijing_time)
114
+ t = time.strftime('%Y-%m-%d %H:%M:%S', beijing_struct_time)
115
+
116
+ # 获取查询参数
117
+ query_params = parse_qs(parsed_url.query)
118
+ try:
119
+ ConnectionId = query_params['ConnectionId'][0]
120
+ # return
121
+ except KeyError:
122
+ pass
123
+ # 打印查询参数
124
+ print(t, ' ', url)
125
+ # print(query_params)
126
+ # 获取Sec-MS-GEC和Sec-MS-GEC-Version
127
+ try:
128
+ Sec_MS_GEC = query_params['Sec-MS-GEC'][0]
129
+ Sec_MS_GEC_Version = query_params['Sec-MS-GEC-Version'][0]
130
+ print(f"{t} Sec-MS-GEC: {Sec_MS_GEC}\nSec-MS-GEC-Version: {Sec_MS_GEC_Version}")
131
+ data = {
132
+ "Sec-MS-GEC": Sec_MS_GEC,
133
+ "Sec-MS-GEC-Version": Sec_MS_GEC_Version,
134
+ "last_update": int(time.time()),
135
+ "last_update_format(UTC +8)": t
136
+ }
137
+
138
+ body = {"key": "edge",
139
+ "value": json.dumps(data), # 将字典转换为 JSON 字符串
140
+ }
141
+ url = 'https://edge-sec.myaitool.top/lsjafadslhhi'
142
+ with httpx.Client() as client:
143
+ response = client.post(url, json=body)
144
+ print(response.text)
145
+ return data
146
+ except Exception as e:
147
+ print(f'cuowu: {e}')
148
+ pass
149
+ # 遍历查询参数
150
+ # for key, value in query_params.items():
151
+ # if key == 'Sec-MS-GEC':
152
+ # print(f"{key}: {value}")
153
+ # print(f"Query parameters for {url}: {query_params}")
154
+
155
+
156
+ addons = [ListenComment()]
157
+
158
+ if __name__ == '__main__':
159
+ # set_proxy()
160
+ # atexit.register(close_proxy) '--verbose',
161
+ # browser = open_browser()
162
+ b = get_info()
163
+ # atexit.register(b.quit)
164
+ mitmdump(['-s', __file__, '-p 12346', '-q', ])