吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4765|回复: 56
收起左侧

[原创工具] PC版微信自动锁定工具//6.29测试几天后发现不好用,抱歉各位

  [复制链接]
文火慢燉 发表于 2025-6-26 17:12
本帖最后由 文火慢燉 于 2025-6-29 15:13 编辑

人生第一个小软件,孬好的大佬们凑合看
这个软件是为了实现离开办公室的时候自动锁定微信
前提是手机和电脑都在同一个wifi下
手机离开当前wifi后,微信自动锁定
手机需提前设置固定ip
时间间隔建议30秒,因为会连续两次ping不通才会锁定
关闭软件自动缩小到后台运行,右键退出和现实
我也不知道为什么这么点代码这么大的exe,
360会报,不放心可以复制代码自己打包,
技术不精,可能会有误锁定,我也不清楚是咋回事。。。。

测试几天后发现不好用,要么假死要么不锁的,
我也没勇气来论坛看回复,向各位下载试用过的朋友表示歉意
至今搞不清楚是哪里的问题...
管理看到麻烦删帖,下次发帖前会多测试几天{:1_896:}


成品如下:
https://wwpu.lanzouo.com/iMcyw2zlv2gd


代码如下:
[Python] 纯文本查看 复制代码
import tkinter as tk
from tkinter import messagebox, scrolledtext
import threading
import time
import subprocess
import pyautogui
from pystray import MenuItem as item
import pystray
from PIL import Image, ImageDraw
import queue

class WeChatLocker:
    def __init__(self, root):
        self.root = root
        self.root.title("微信自动锁")

        # --- GUI Elements ---
        main_frame = tk.Frame(root)
        main_frame.pack(padx=10, pady=10)

        tk.Label(main_frame, text="手机IP地址:").grid(row=0, column=0, sticky='w', pady=2)
        self.ip_entry = tk.Entry(main_frame, width=25)
        self.ip_entry.grid(row=0, column=1, pady=2)

        tk.Label(main_frame, text="间隔时间(秒):").grid(row=1, column=0, sticky='w', pady=2)
        self.interval_entry = tk.Entry(main_frame, width=25)
        self.interval_entry.grid(row=1, column=1, pady=2)
        self.interval_entry.insert(0, "5")

        button_frame = tk.Frame(main_frame)
        button_frame.grid(row=2, columnspan=2, pady=10)
        self.start_button = tk.Button(button_frame, text="运行", command=self.start_locking)
        self.start_button.pack(side=tk.LEFT, padx=5)
        self.stop_button = tk.Button(button_frame, text="停止", command=self.stop_locking, state=tk.DISABLED)
        self.stop_button.pack(side=tk.LEFT, padx=5)

        tk.Label(main_frame, text="运行信息:").grid(row=3, column=0, sticky='w', pady=2)
        self.info_display = scrolledtext.ScrolledText(main_frame, height=10, width=40, state='normal')
        self.info_display.grid(row=4, columnspan=2, pady=5)
        self.info_display.insert(tk.END, "为避免误ping,连续2次ping不通才会锁定\n建议间隔时间30秒(30秒×2=1分钟)\n52pojie@文火慢燉\n")
        self.info_display.config(state='disabled')

        # --- State and Threading ---
        self.is_running = False
        self.thread = None
        self.message_queue = queue.Queue()

        # --- System Tray and Window Management ---
        self.root.protocol("WM_DELETE_WINDOW", self.hide_to_tray)
        self.icon = None
        self.process_queue()

    def log_message(self, message):
        self.message_queue.put(message)

    def process_queue(self):
        try:
            while True:
                message = self.message_queue.get_nowait()
                self.info_display.config(state='normal')
                self.info_display.insert(tk.END, f"{time.strftime('%H:%M:%S')} - {message}\n")
                self.info_display.see(tk.END)
                self.info_display.config(state='disabled')
        except queue.Empty:
            pass
        self.root.after(100, self.process_queue)

    def create_image(self):
        image = Image.new('RGB', (64, 64), 'black')
        dc = ImageDraw.Draw(image)
        dc.rectangle((10, 10, 54, 54), fill='white')
        return image

    def hide_to_tray(self):
        self.root.withdraw()
        image = self.create_image()
        menu = (item('显示', self.show_window), item('退出', self.quit_window))
        self.icon = pystray.Icon("WeChatLocker", image, "微信自动锁定", menu)
        self.icon.run()

    def show_window(self):
        if self.icon:
            self.icon.stop()
        self.root.deiconify()

    def quit_window(self):
        self.stop_locking()
        if self.icon:
            self.icon.stop()
        self.root.destroy()

    def start_locking(self):
        ip = self.ip_entry.get()
        interval_str = self.interval_entry.get()

        if not ip:
            messagebox.showerror("错误", "请输入IP地址")
            return
        try:
            interval = int(interval_str)
            if interval <= 0:
                raise ValueError
        except ValueError:
            messagebox.showerror("错误", "间隔时间必须是正整数")
            return

        self.is_running = True
        self.start_button.config(state=tk.DISABLED)
        self.stop_button.config(state=tk.NORMAL)
        self.log_message(f"开始监控IP: {ip}")

        self.thread = threading.Thread(target=self.ping_loop, args=(ip, interval), daemon=True)
        self.thread.start()

    def stop_locking(self):
        if self.is_running:
            self.is_running = False
            self.log_message("监控已停止")
        self.start_button.config(state=tk.NORMAL)
        self.stop_button.config(state=tk.DISABLED)

    def ping_loop(self, ip, interval):
        was_pingable = True
        failure_count = 0
        while self.is_running:
            command = ["ping", "-n", "1", "-w", "2000", ip]
            ping_success = False
            try:
                result = subprocess.run(
                    command, 
                    check=False, 
                    capture_output=True, 
                    text=True, 
                    creationflags=subprocess.CREATE_NO_WINDOW
                )
                if result.returncode == 0:
                    ping_success = True
            except Exception as e:
                self.log_message(f"Ping命令执行出错: {e}")

            if ping_success:
                failure_count = 0
            else:
                failure_count += 1

            is_pingable = failure_count < 2

            if is_pingable:
                if not was_pingable:
                    self.log_message(f"Ping {ip} 成功,连接已恢复。")
                else:
                    self.log_message(f"Ping {ip} 成功,状态正常 (失败次数: {failure_count})")
            else:  # is_pingable is False
                if was_pingable:
                    self.log_message(f"Ping {ip} 连续失败2次,准备锁定微信。")
                    self.lock_wechat()
                else:
                    self.log_message(f"Ping {ip} 持续失败 (次数: {failure_count}),微信已锁定,无需重复操作。")

            was_pingable = is_pingable

            for _ in range(interval):
                if not self.is_running:
                    break
                time.sleep(1)

    def lock_wechat(self):
        try:
            self.log_message("执行快捷键 Ctrl+Alt+W 打开微信")
            pyautogui.hotkey('ctrl', 'alt', 'w')
            time.sleep(0.5) # 等待微信窗口出现
            self.log_message("执行快捷键 Ctrl+L 锁定微信")
            pyautogui.hotkey('ctrl', 'l')
            time.sleep(0.5) # 等待锁定完成
            pyautogui.hotkey('ctrl', 'alt', 'w') # 再次执行打开微信快捷键来隐藏微信
            self.log_message("微信已锁定并隐藏")
        except Exception as e:
            self.log_message(f"锁定微信时出错: {e}")

if __name__ == "__main__":
    root = tk.Tk()
    app = WeChatLocker(root)
    root.mainloop()
image.png

免费评分

参与人数 17吾爱币 +20 热心值 +16 收起 理由
抱薪风雪雾 + 1 + 1 谢谢@Thanks!
z1017 + 1 谢谢@Thanks!
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
yushao322 + 1 + 1 热心回复!
zffz + 1 + 1 谢谢@Thanks!
colaya + 1 谢谢@Thanks!
peishao + 1 + 1 我很赞同!
黄金体验 + 1 + 1 谢谢@Thanks!
confiant + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
wer1023 + 1 + 1 我很赞同!
dengbin + 1 + 1 鼓励转贴优秀软件安全工具和文档!
vr4u + 1 我就从来没想过这个问题
alderaan + 1 + 1 热心回复!
sgzdmsz + 1 + 1 用心讨论,共获提升!
旧忆 + 1 + 1 一直想要个这样功能的
cioceo + 1 + 1 我很赞同!
gwsymm + 1 + 1 我很赞同!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

chenzhigang 发表于 2025-6-26 18:54
提个建议 ip会变 监控手机的mac 地址
Piz.liu 发表于 2025-6-26 20:38
kaixin15A 发表于 2025-7-4 08:38
支持原创,手机微信自带的锁定功能就挺好用,你可以设置场景自动执行脚本,现在手机好像都用了
af8889 发表于 2025-6-26 17:33
谢谢分享!!看看好用吧
Shisan0979 发表于 2025-6-26 17:58
感谢分享
interji 发表于 2025-6-26 18:18
思维挺巧妙的
q3125418 发表于 2025-6-26 18:21
l论坛有个作品。。摄像头锁定的。只要离开摄像头没拍到你就锁定。。
lyj901024 发表于 2025-6-26 18:34
q3125418 发表于 2025-6-26 18:21
l论坛有个作品。。摄像头锁定的。只要离开摄像头没拍到你就锁定。。

论坛那个是  没拍到人吧  只要有人就不会锁定,不是指定的某个人
umbrella_red 发表于 2025-6-26 19:19
挺好的软件,感谢分享
y294945022 发表于 2025-6-26 19:37
微信自动锁定是什么意思 ? 锁电脑 ?还是电脑上只能操作微信其它的都无法操作?
小卷 发表于 2025-6-26 19:38
chenzhigang 发表于 2025-6-26 18:54
提个建议 ip会变 监控手机的mac 地址

现在有些手机连wifi mac地址都会随机 要手动
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-4-15 07:31

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表