From 3d8fd4112774f93772741ce58387311779da431f Mon Sep 17 00:00:00 2001 From: cheney Date: Mon, 13 Jul 2026 19:55:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E6=81=AF=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keep-awake.js | 43 +++++++++++++++++++++++++++++++++++++++++++ proxy/config.ini | 3 ++- proxy/proxy_client.py | 4 ++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 keep-awake.js diff --git a/keep-awake.js b/keep-awake.js new file mode 100644 index 0000000..9a16500 --- /dev/null +++ b/keep-awake.js @@ -0,0 +1,43 @@ +const { execSync } = require('child_process'); + +const POWER_SHELL = 'powershell -NoProfile -Command'; + +function getMousePos() { + const cmd = `${POWER_SHELL} "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Cursor]::Position"`; + const output = execSync(cmd, { windowsHide: true }).toString(); + const match = output.match(/X=(\d+).*Y=(\d+)/); + if (!match) throw new Error('Failed to get mouse position'); + return { x: parseInt(match[1], 10), y: parseInt(match[2], 10) }; +} + +function setMousePos(x, y) { + const cmd = `${POWER_SHELL} "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(${x}, ${y})"`; + execSync(cmd, { windowsHide: true }); +} + +const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); + +async function main() { + console.log('已启动防息屏,每 15 秒移动鼠标 1 像素再移回原位。Ctrl+C 停止。\n'); + let moving = false; + + process.on('SIGINT', () => { + console.log('\n已停止。'); + process.exit(0); + }); + + while (true) { + const orig = getMousePos(); + setMousePos(orig.x + 1, orig.y); + console.log(`→ 右移 1 像素 (${orig.x}, ${orig.y}) → (${orig.x + 1}, ${orig.y})`); + await sleep(14000); + setMousePos(orig.x, orig.y); + console.log(`← 移回原位 (${orig.x + 1}, ${orig.y}) → (${orig.x}, ${orig.y})`); + await sleep(1000); + } +} + +main().catch((err) => { + console.error('出错:', err.message); + process.exit(1); +}); diff --git a/proxy/config.ini b/proxy/config.ini index 53f73bd..184ebcf 100644 --- a/proxy/config.ini +++ b/proxy/config.ini @@ -1,4 +1,5 @@ [proxy] + # 目标服务器配置 # 协议支持: http, https # protocol = https @@ -13,4 +14,4 @@ target_port = 443 # 另一个备用配置 # protocol = http # target_host = 192.168.1.100 -# target_port = 8080 +# target_port = 8080 \ No newline at end of file diff --git a/proxy/proxy_client.py b/proxy/proxy_client.py index 0ec8870..cd07c72 100644 --- a/proxy/proxy_client.py +++ b/proxy/proxy_client.py @@ -4,6 +4,7 @@ import sys import configparser import os + def load_config(config_path='config.ini'): """加载配置文件""" config = configparser.ConfigParser() @@ -43,6 +44,7 @@ def load_config(config_path='config.ini'): def handle_request(sock, target_host, target_port): """处理从A设备收到的请求,转发到目标网站""" + try: # 接收来自A设备的请求 request = b"" @@ -102,8 +104,10 @@ def connect_to_a_device(a_host, a_port, target_host, target_port): time.sleep(3) def main(): + # 加载配置 config = load_config() + # 解析命令行参数 if len(sys.argv) < 3: