欢迎各位兄弟 发布技术文章
这里的技术是共享的
在 Python 中,你可以通过以下几种方式来判断系统是否存在 agt3tool 命令,从而间接判断 IP-Guard 是否安装:
which 或 where 命令(跨平台)或者使用 subprocess 检查 # OK 有大用pythonimport subprocess import shutil def is_ipguard_installed(): # 检查命令是否存在(Linux/macOS/Windows均可) if shutil.which('agt3tool') is not None: return True # 或者使用 subprocess 检查 try: subprocess.run(['agt3tool', '--version'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True) return True except (FileNotFoundError, subprocess.CalledProcessError): return False if is_ipguard_installed(): print("IP-Guard 已安装(检测到 agt3tool 命令)") else: print("未检测到 IP-Guard 安装")
pythonimport winreg def check_ipguard_via_registry(): try: key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\TrendMicro\IP-Guard") winreg.CloseKey(key) return True except FileNotFoundError: return False if check_ipguard_via_registry(): print("通过注册表检测到 IP-Guard 安装") else: print("注册表中未找到 IP-Guard")
pythonimport psutil # 需要安装 pip install psutil def is_ipguard_running(): for proc in psutil.process_iter(['name']): if proc.info['name'].lower() in ('ipguard.exe', 'agt3tool.exe'): return True return False
agt3tool 是 IP-Guard 的一个命令行工具,但不同版本可能有不同的名称
某些环境下可能需要管理员权限才能正确检测
IP-Guard 可能有多种安装方式和组件,单一检测方法可能有遗漏
在 Linux/Mac 和 Windows 上的检测方式可能不同
最可靠的方法是结合多种检测方式,或参考 IP-Guard 官方文档确认其安装标志。