# network-collector **Repository Path**: wangbincode/network-collector ## Basic Information - **Project Name**: network-collector - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-15 - **Last Updated**: 2026-03-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 网络采集器 - Network Collector 跨平台进程和网络信息采集工具,支持 Linux 和 Windows。 ## 功能 ### 阶段一:采集 ✅ - ✅ 本地采集:进程列表、TCP 连接、系统信息 - ✅ 远程采集:通过 SSH 采集远程机器(支持密码/密钥认证) - ✅ 批量采集:JSON 配置文件管理多台目标机器 - ✅ 采集存储:自动保存到 `collections/` 目录 - ✅ 历史对比:对比多次采集结果,分析变化 ## 安装 ```bash pip install -r requirements.txt ``` ## 安装 ### Windows 一键安装 双击运行 `install.bat`,自动安装依赖。 ### 手动安装 ```bash pip install psutil paramiko ``` ## 使用 ### 本地采集 ```bash python collector.py ``` ### 查看历史采集 ```bash python storage.py ``` ### 对比采集结果 ```bash # 对比最近两次 python compare.py # 对比指定文件 python compare.py collections/before_xxx.json collections/after_xxx.json ``` ### 远程采集(单机) ```bash # 密码认证 python remote_collector.py -H 192.168.1.100 -u root -p 123456 # 密钥认证 python remote_collector.py -H 192.168.1.100 -u root -k ~/.ssh/id_rsa # 自定义端口 python remote_collector.py -H 192.168.1.100 -P 2222 -u admin -p secret ``` ### 批量采集 创建 `targets.json` 配置文件: ```json [ {"host": "192.168.1.100", "port": 22, "username": "root", "password": "123456"}, {"host": "192.168.1.101", "port": 22, "username": "admin", "key_file": "~/.ssh/id_rsa"} ] ``` 运行: ```bash python remote_collector.py -c targets.json -o results.json ``` ### 作为模块导入 ```python from collector import collect_all, get_process_list, get_network_connections from remote_collector import collect_remote, collect_multiple # 本地采集 data = collect_all() # 远程采集 result = collect_remote('192.168.1.100', 22, 'root', password='123456') # 批量采集 targets = [{'host': '192.168.1.100', 'username': 'root', 'password': '123456'}] collect_multiple(targets) ``` ## 输出示例 采集结果保存为 `system_snapshot.json`,包含: ```json { "timestamp": "2026-03-15 14:30:00", "system": { "platform": "Linux", "hostname": "server01", "cpu_count": 4, "memory_total_gb": 8.0 }, "processes": [...], "network": [...] } ``` ## 依赖 - Python 3.6+ - psutil ## 许可证 MIT