公告
  
喜讯:2024系统全面升级!现在所有资源免费下载!全部内容免费使用!
授权码获取请关注公众号“鸿盟创客”
查看详情

朕已阅

易支付-免签支付平台

Python实现的微信进群检测(防骚扰、防捣乱、防同行)

admin 千秋月 关注 管理组 论坛神话
发表于程序代码版块 技术杂文
Image

摘要

为了监控捣乱者、骚扰者、同行等人群加入微信群,我写了一个监控,实时监控这个人有没有偷偷混进群,如果检测到,就给你手机发送通知。

代码

import uiautomation as automation
import requests
import time

def send_results(results, url):
    payload = {"results": results}
    try:
        response = requests.post(url, json=payload)
        if response.status_code == 200:
            print("---检测结果已发送至服务器---")
        else:
            print(f"发送失败,状态码: {response.status_code}")
    except requests.RequestException as e:
        print(f"发送请求时发生错误: {e}")

def get_filtered_controls_at_depth(control, target_depth, filter_strings, bypass_strings, current_depth=0, detected_controls=None):
    if detected_controls is None:
        detected_controls = set()
    
    results = []
    try:
        if current_depth == target_depth:
            # 如果控件名称包含任何绕过字符串,则跳过该控件
            if any(bypass_string in control.Name for bypass_string in bypass_strings):
                return results
            
            # 如果控件名称包含任何过滤字符串且该控件未被检测过,则添加到结果中
            if any(filter_string in control.Name for filter_string in filter_strings) and control.Name not in detected_controls:
                # 只返回控件内容
                results.append(control.Name)
                detected_controls.add(control.Name)
    except Exception as e:
        print(f"处理控件信息时发生错误: {e}")
    
    try:
        children = control.GetChildren()
        for child in children:
            results.extend(get_filtered_controls_at_depth(child, target_depth, filter_strings, bypass_strings, current_depth + 1, detected_controls))
    except Exception as e:
        print(f"获取子控件时发生错误: {e}")
    
    return results

def monitor_chat_window(target_depth, filter_strings, bypass_strings, interval, url):
    detected_controls = set()
    while True:
        try:
            # 获取名为 "ChatWnd" 的窗口
            window = automation.WindowControl(ClassName="ChatWnd")
            if window.Exists(0, 0):
                results = get_filtered_controls_at_depth(window, target_depth, filter_strings, bypass_strings, detected_controls=detected_controls)
                
                # 打印结果
                if results:
                    for result in results:
                        print(result)
                        send_results(result, url)
            else:
                # 移除每次循环中输出的 "持续为您监控中..."
                pass
        except Exception as e:
            print(f"主循环中发生错误: {e}")
            send_results(f"主循环中发生错误: {e}", url)
        
        # 等待指定的时间间隔
        time.sleep(interval)

if __name__ == "__main__":
    # 配置参数
    target_depth = 12  # 检测的控件的深度(这里是固定的检测进群记录就是深度12别修改)
    filter_strings = ["蔡徐坤"]  # 要检测的字符串
    bypass_strings = ["移出了群聊"]  # 要绕过检测的字符串
    interval = 1  # 检测的频率(秒)
    url = "https://xxxxxxxxx"  # 接收监控结果的URL

    try:
        print("持续为您监控中...")  # 只输出一次
        # 开始监控
        monitor_chat_window(target_depth, filter_strings, bypass_strings, interval, url)
    except KeyboardInterrupt:
        print("检测程序被中断,正在退出...")
        # 发送中断信息到服务器
        send_results("检测程序被中断", url)
        print("程序已退出")

这段代码的主要功能是通过监控名为 “ChatWnd” 的窗口,检查控件的名称是否包含特定的过滤字符串,并将检测结果通过 HTTP POST 请求发送到指定的URL,其背后的原理是通过 Python uiautomation 这个库去读取微信电脑版界面的控件去解析到具体的信息。


如何使用

打开微信电脑版你要监控的群单独拉出来

在代码中的【要检测的字符串】中配置你要检测的微信用户昵称

配置接收通知的URL

CMD运行python程序即可开始检测

整个过程请保持你要监控的群是不关闭的状态(最小化是可以的)

打开微信电脑版你要监控的群单独拉出来

Image

CMD运行python程序即可开始检测

Image

接收到通知

Image

本文章最后由 admin2024-07-30 14:02 编辑
评论列表 评论
发布评论

评论: Python实现的微信进群检测(防骚扰、防捣乱、防同行)

600G防护精品服务器 免备案高防云服务器



600G防护精品服务器 免备案高防云服务器 可以免费发外链的论坛 百度万词霸屏


免责声明
本站资源,均来自网络,版权归原作者,所有资源和文章仅限用于学习和研究目的 。 不得用于商业或非法用途,否则,一切责任由该用户承担 !

请求资源或报告无效资源,请点击[反馈中心]


侵权删除请致信 E-Mail:chengfengad@gmail.com
已有0次打赏
(0) 分享
分享
取消