Skip to content

Repository files navigation

戒网 / NetBlocker

一个无需 Root、完全在本机运行的 Android 定时断网工具。

A no-root Android app that blocks network access on a configurable daily schedule, entirely on the device.

中文 · English

中文

功能

  • 可配置每天开始断网和恢复网络的时间,默认时段为 22:00 至次日 07:00
  • 支持当天结束及跨午夜的计划时段,并自动阻止 IPv4 和 IPv6 网络流量。
  • 使用 Android 官方 VpnService,不需要 Root 或设备所有者权限。
  • 支持开机恢复、精确定时、运行状态通知和 60 秒断网测试。
  • 关键操作受应用内管理密码保护。
  • 包名:com.iamlouis.netblocker
  • 支持 Android 8.0(API 26)及以上版本,包括 Android 平板。
  • 当前版本名采用 1.0.1.build-yyyyMMddHHmmss.SSS,构建时间使用 Asia/Shanghai 时区并精确到毫秒。

工作原理与隐私

禁网时段内,应用创建一个仅存在于本机的虚拟 VPN 网卡,把全部 IPv4 和 IPv6 流量路由到该网卡并直接丢弃。应用不连接任何服务器,也不解析、记录或 上传网络数据。Wi-Fi 和移动网络无线电本身不会关闭,因此系统图标仍可能显示 “已连接”。

使用说明

  1. 安装并打开“戒网”。
  2. 使用初始管理密码 HU,3k 解锁设置,并立即修改为自己的密码。
  3. 点击“每日断网计划”,依次选择开始断网和恢复网络的时间。
  4. 点击“启用戒网计划”,同意 Android 的 VPN 连接请求。
  5. 建议允许运行通知、精确定时,并取消系统对本应用的电池优化。
  6. 可使用“测试断网 60 秒”和“个人版自检”验证状态。

管理密码使用带随机盐的 PBKDF2-HMAC-SHA256 摘要保存。公开的初始密码只适合 首次设置,不构成安全秘密。

个人版限制

  • Android 同一时间只能启用一个 VPN;切换到其他 VPN 会使本应用失效。
  • 普通 APK 无法阻止设备所有者从系统设置中强行停止、清除数据或卸载应用。
  • 请勿同时开启系统的“始终开启 VPN”或“无 VPN 时阻止连接”;本应用在允许 上网时段会主动关闭虚拟网卡,这些系统选项可能导致白天也无法联网。
  • 每日计划使用设备当前时区;开始和恢复时间不能设置为同一时刻。

构建与测试

需要 JDK 17 和 Android SDK 35。仓库包含 Gradle Wrapper:

git clone https://github.com/louisir/NetBlocker.git
cd NetBlocker
.\gradlew.bat assembleDebug lintDebug

macOS 或 Linux:

./gradlew assembleDebug lintDebug

调试 APK 位于:

app/build/outputs/apk/debug/app-debug.apk

通过 ADB 安装:

adb install -r .\app\build\outputs\apk\debug\app-debug.apk

纯 Java 时间窗口自检:

javac -encoding UTF-8 -d build/self-test app/src/main/java/com/iamlouis/netblocker/TimeWindow.java tools/com/iamlouis/netblocker/TimeWindowSelfTest.java
java -cp build/self-test com.iamlouis.netblocker.TimeWindowSelfTest

私有签名密钥、已签名 APK、本地 SDK、构建缓存和本地配置不会提交到仓库。

English

Features

  • Lets you configure the daily block and restore times; the default interval is 22:00 until 07:00 the next morning.
  • Supports same-day and overnight intervals and blocks both IPv4 and IPv6 traffic during the configured window.
  • Uses Android's official VpnService; no root or device-owner privileges are required.
  • Restores its schedule after boot, supports exact alarms, shows a persistent status notification, and includes a 60-second blocking test.
  • Protects sensitive in-app actions with an administrator password.
  • Application ID: com.iamlouis.netblocker.
  • Supports Android 8.0 (API 26) and newer, including Android tablets.
  • Current version names use 1.0.1.build-yyyyMMddHHmmss.SSS, with a millisecond-precision build time in the Asia/Shanghai time zone.

How it works and privacy

During the blocking window, NetBlocker creates an on-device VPN interface, routes all IPv4 and IPv6 traffic into it, and discards every packet. It does not connect to a server and does not inspect, log, or upload network traffic. The Wi-Fi and cellular radios remain enabled, so Android may still display a connected network icon.

Getting started

  1. Install and open NetBlocker (戒网).
  2. Unlock settings with the initial password HU,3k, then change it immediately.
  3. Tap the daily schedule card and choose the block and restore times.
  4. Tap the enable button and approve Android's VPN connection prompt.
  5. For reliable operation, allow notifications and exact alarms, and exempt the app from battery optimization.
  6. Use the 60-second test and the in-app self-check to verify the setup.

Passwords are stored as salted PBKDF2-HMAC-SHA256 hashes. The published initial password is intended only for first-time setup and is not a secret.

Personal-edition limitations

  • Android permits only one active VPN at a time. Starting another VPN revokes NetBlocker's VPN access.
  • A regular Android app cannot prevent the device owner from force-stopping, clearing, or uninstalling it through system settings.
  • Do not combine this app with Android's “Always-on VPN” or “Block connections without VPN” options. NetBlocker intentionally closes its VPN outside the blocking window, so those options may also block daytime access.
  • The daily schedule follows the device's current time zone; its start and end times cannot be identical.

Build and test

Install JDK 17 and Android SDK 35. The repository includes the Gradle Wrapper:

git clone https://github.com/louisir/NetBlocker.git
cd NetBlocker
.\gradlew.bat assembleDebug lintDebug

On macOS or Linux:

./gradlew assembleDebug lintDebug

The debug APK is generated at:

app/build/outputs/apk/debug/app-debug.apk

Install it with ADB:

adb install -r .\app\build\outputs\apk\debug\app-debug.apk

Run the standalone Java schedule self-test with:

javac -encoding UTF-8 -d build/self-test app/src/main/java/com/iamlouis/netblocker/TimeWindow.java tools/com/iamlouis/netblocker/TimeWindowSelfTest.java
java -cp build/self-test com.iamlouis.netblocker.TimeWindowSelfTest

Private signing keys, signed APKs, local SDK files, build caches, and local configuration are intentionally excluded from version control.

License / 许可证

NetBlocker is released under the MIT License. An unofficial Simplified Chinese translation is provided for convenience.

NetBlocker 采用 MIT 许可证 发布,并提供一份便于阅读的 非官方简体中文译本

About

无需 Root 的 Android 定时断网工具 / No-root scheduled network blocker for Android

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages