|
1 | 1 | # NetMonitor |
2 | 2 |
|
3 | | -<p align="center"> |
4 | | - <b>Android 网络安全监控工具</b><br> |
5 | | - 实时监控设备网络连接 · VPN 抓包分析 · 真实 IP 暴露检测 |
6 | | -</p> |
| 3 | +Android network security monitoring app for inspecting active connections, local VPN capture, and potential real-IP exposure. |
7 | 4 |
|
8 | | ---- |
| 5 | +This project is focused on practical mobile network visibility: what apps are connecting, where traffic is going, and whether traffic may bypass the expected route. |
9 | 6 |
|
10 | | -## 功能特性 |
| 7 | +## What It Does |
11 | 8 |
|
12 | | -- **实时连接监控** — 解析 `/proc/net/tcp|udp` 获取所有活跃网络连接,显示协议、IP、端口、应用归属 |
13 | | -- **VPN 数据包捕获** — 本地 VPN 隧道抓包,无需 Root 即可查看所有出入站流量 |
14 | | -- **真实 IP 暴露检测** — 自动扫描连接列表,识别 IP 泄漏和端口暴露风险并记录 |
15 | | -- **Root 增强模式** — 有 Root 权限时可获取更完整的网络信息(netstat、iptables、ARP 表等) |
16 | | -- **连接筛选过滤** — 按协议、状态、应用名等条件筛选连接和数据包 |
17 | | -- **暴露日志持久化** — JSON 文件存储暴露记录,支持导出文本报告 |
18 | | -- **系统诊断** — 一键生成设备网络诊断报告(Root 状态、/proc/net 可读性、权限、内存等) |
| 9 | +- Monitors active TCP/UDP connections from Android network tables |
| 10 | +- Shows protocol, IP, port, state, and app ownership where available |
| 11 | +- Provides local VPN-based packet capture without requiring root |
| 12 | +- Records potential exposure events for later review |
| 13 | +- Offers root-enhanced diagnostics when root is available |
| 14 | +- Generates device/network diagnostic reports |
19 | 15 |
|
20 | | -## 技术栈 |
| 16 | +## Features |
21 | 17 |
|
22 | | -| 组件 | 技术 | |
23 | | -|------|------| |
24 | | -| 语言 | Kotlin 1.9.24 | |
25 | | -| 最低版本 | Android 8.0 (API 26) | |
26 | | -| 目标版本 | Android 15 (API 35) | |
27 | | -| 架构 | MVVM (ViewModel + LiveData + Repository) | |
28 | | -| 异步 | Kotlin Coroutines + SharedFlow | |
29 | | -| 导航 | Jetpack Navigation | |
30 | | -| 构建 | Gradle Kotlin DSL + AGP 8.5.2 | |
| 18 | +| Feature | Description | |
| 19 | +| --- | --- | |
| 20 | +| Connection monitor | Reads active network connections and maps them to apps when possible | |
| 21 | +| VPN packet capture | Uses Android `VpnService` to observe outbound/inbound traffic locally | |
| 22 | +| Exposure detection | Flags suspicious direct connections and possible real-IP leaks | |
| 23 | +| Root mode | Uses extra network commands when root permission is available | |
| 24 | +| Filtering | Filters by protocol, state, app, and traffic type | |
| 25 | +| Export | Stores exposure logs and exports diagnostic reports | |
31 | 26 |
|
32 | | -## 项目结构 |
| 27 | +## Good For |
33 | 28 |
|
34 | | -``` |
| 29 | +- Android network visibility |
| 30 | +- VPN leak investigation |
| 31 | +- App traffic auditing |
| 32 | +- Rooted-device network diagnostics |
| 33 | +- Learning how Android network monitoring works |
| 34 | + |
| 35 | +## Tech Stack |
| 36 | + |
| 37 | +| Area | Tech | |
| 38 | +| --- | --- | |
| 39 | +| Language | Kotlin | |
| 40 | +| Platform | Android 8.0+ | |
| 41 | +| Architecture | MVVM, ViewModel, LiveData, Repository | |
| 42 | +| Async | Kotlin Coroutines, SharedFlow | |
| 43 | +| Capture | Android `VpnService`, `/proc/net/*`, optional root commands | |
| 44 | +| Build | Gradle Kotlin DSL | |
| 45 | + |
| 46 | +## Project Structure |
| 47 | + |
| 48 | +```text |
35 | 49 | app/src/main/java/com/netmonitor/app/ |
36 | | -├── Constants.kt # 全局常量集中管理 |
37 | | -├── MainActivity.kt # 主活动 |
38 | | -├── NetMonitorApp.kt # Application 初始化 |
39 | | -├── model/ |
40 | | -│ ├── ConnectionInfo.kt # 网络连接数据模型 |
41 | | -│ ├── ExposureRecord.kt # 暴露记录数据模型 |
42 | | -│ ├── FilterConfig.kt # 筛选配置 |
43 | | -│ └── PacketInfo.kt # 数据包信息模型 |
44 | | -├── repository/ |
45 | | -│ └── NetworkRepository.kt # 数据仓库层 |
46 | | -├── receiver/ |
47 | | -│ └── BootReceiver.kt # 开机自启广播 |
48 | | -├── service/ |
49 | | -│ ├── NetworkMonitorService.kt # 网络监控前台服务 |
50 | | -│ └── PacketCaptureVpnService.kt # VPN 抓包服务 |
51 | | -├── ui/ |
52 | | -│ ├── adapter/ # RecyclerView 适配器 |
53 | | -│ ├── connections/ # 连接列表页 |
54 | | -│ ├── exposure/ # 暴露日志页 |
55 | | -│ ├── home/ # 主页总览 |
56 | | -│ ├── packets/ # 抓包列表页 |
57 | | -│ └── settings/ # 设置页 |
58 | | -├── util/ |
59 | | -│ ├── AppLogger.kt # 应用日志(环形缓冲区) |
60 | | -│ ├── ExposureLogManager.kt # 暴露记录管理(线程安全) |
61 | | -│ ├── NetworkParser.kt # /proc/net 解析器 |
62 | | -│ ├── PacketBus.kt # 数据包事件总线 (SharedFlow) |
63 | | -│ └── RootShell.kt # Root 命令执行(输入校验) |
64 | | -└── viewmodel/ |
65 | | - └── MonitorViewModel.kt # 监控 ViewModel(防抖更新) |
| 50 | +├── model/ # connection, packet, exposure, filter models |
| 51 | +├── repository/ # network data layer |
| 52 | +├── service/ # foreground monitor and VPN capture services |
| 53 | +├── ui/ # home, connections, packets, exposure, settings |
| 54 | +├── util/ # parsers, logging, root shell, event bus |
| 55 | +└── viewmodel/ # monitor view model |
66 | 56 | ``` |
67 | 57 |
|
68 | | -## 构建运行 |
| 58 | +## Build |
69 | 59 |
|
70 | 60 | ```bash |
71 | | -# 克隆仓库 |
72 | 61 | git clone https://github.com/521w/NetMonitor.git |
73 | 62 | cd NetMonitor |
74 | | - |
75 | | -# 构建 Debug APK |
76 | 63 | ./gradlew assembleDebug |
| 64 | +``` |
| 65 | + |
| 66 | +Install the debug APK: |
77 | 67 |
|
78 | | -# 安装到设备 |
| 68 | +```bash |
79 | 69 | adb install app/build/outputs/apk/debug/app-debug.apk |
80 | 70 | ``` |
81 | 71 |
|
82 | | -## 权限说明 |
| 72 | +## Permissions |
| 73 | + |
| 74 | +The app requests network, VPN, foreground-service, notification, package-query, boot, storage, and optional root/system-level permissions. Some protected permissions only work on rooted, system, or debug environments. |
| 75 | + |
| 76 | +## Notes |
83 | 77 |
|
84 | | -| 权限 | 用途 | |
85 | | -|------|------| |
86 | | -| `INTERNET` | 网络访问(VPN 隧道) | |
87 | | -| `ACCESS_NETWORK_STATE` | 获取网络连接状态 | |
88 | | -| `ACCESS_WIFI_STATE` | 获取 WiFi 信息 | |
89 | | -| `ACCESS_FINE_LOCATION` | 获取 WiFi SSID(Android 要求) | |
90 | | -| `FOREGROUND_SERVICE` | 后台持续监控 | |
91 | | -| `POST_NOTIFICATIONS` | 显示监控状态通知 | |
92 | | -| `QUERY_ALL_PACKAGES` | 识别连接所属应用 | |
93 | | -| `RECEIVE_BOOT_COMPLETED` | 开机自启 | |
| 78 | +- VPN capture uses a local Android VPN tunnel and does not mean traffic is sent to an external VPN provider. |
| 79 | +- Root mode is optional but improves visibility. |
| 80 | +- Android versions and OEM restrictions may limit how much per-app network data can be collected. |
94 | 81 |
|
95 | | -## 开源协议 |
| 82 | +## License |
96 | 83 |
|
97 | | -MIT License |
| 84 | +MIT |
0 commit comments