功能特性
从预设管理到命令注入防护,每一层都为频繁切换网络的开发者打磨。
保存多套网络配置:网卡、服务名、手动 / DHCP、IP、掩码、网关、DNS,增删改查。
点击卡片或菜单栏项即可切换,可选切换前确认,减少误触。
NSStatusItem 动态预设菜单,与主窗口配合,随手可达。
以记忆的激活预设为锚校验当前网卡配置,被外部更改则提示,恰好匹配则自动采纳。
status / active 子命令,支持 --json,可嵌入 shell 工作流。
XPC LaunchDaemon 执行需要 root 的写操作;免签名脚本安装,免费 Apple ID 即可真机部署。
登录时启动(SMAppService),切换完成后本地通知(UNUserNotificationCenter)。
仅调用绝对路径 /usr/sbin/networksetup;IP / 掩码 / 网关 / DNS 严格 IPv4 校验。
图形界面
SwiftUI 原生界面。预设以卡片排布,激活状态一眼可见;点开关即刻切换,也可常驻菜单栏,在任意应用间快速操作。
设置该预设作用的网络接口与 IPv4 参数。激活后将应用到对应网卡。
IP Switch 的通用偏好。
👆 可交互高保真原型 · 点开关切换预设、✏️ 编辑、⚙️ 设置(数据仅保存在浏览器本地,不影响系统)
NSStatusItem 动态列出全部预设,不打开主窗口也能一键切换,切换后用通知确认生效。
以记忆的激活预设为锚校验当前网卡:被外部更改则提示,恰好匹配则自动采纳。
激活态开关与卡片立即响应,配合 Toast 与可选系统通知,成功或失败都有明确反馈。
命令行
CLI 嵌入 App bundle,也可单独构建;退出码语义明确,适合接入 shell 工作流与自动化。
系统架构
GUI、CLI 与特权 helper 共享核心源码;应用进程只读,写操作经 XPC 送达 root 层的 LaunchDaemon。
切换工作流
触发、探测、特权执行、反馈收尾四阶段;helper 不可用时自动回退,每条失败路径都有明确反馈。
快速构建
macOS 26.5+(Apple Silicon)、Xcode 16+、Swift 5.0。构建与运行无需 Developer ID——helper 采用免签名安装。
# Debug 构建(App + CLI + helper,helper 与 CLI 嵌入 App bundle) xcodebuild -project src/ipswitch/ipswitch.xcodeproj \ -scheme ipswitch -configuration Debug \ -derivedDataPath src/ipswitch/build build # Release 构建(分发用) xcodebuild -project src/ipswitch/ipswitch.xcodeproj \ -scheme ipswitch -configuration Release \ -derivedDataPath src/ipswitch/build build
# 产物:src/ipswitch/build/Build/Products/Debug/ipswitch-cli xcodebuild -project src/ipswitch/ipswitch.xcodeproj \ -target ipswitch-cli -configuration Debug \ -derivedDataPath src/ipswitch/build build # 跑单元测试 xcodebuild -project src/ipswitch/ipswitch.xcodeproj \ -scheme ipswitch -configuration Debug \ -derivedDataPath src/ipswitch/build test
| 构建产物 | 位置 |
|---|---|
| ipswitch.app | src/ipswitch/build/Build/Products/{Debug,Release}/ipswitch.app |
| App 主二进制 | ipswitch.app/Contents/MacOS/ipswitch |
| CLI 二进制(嵌入 App) | ipswitch.app/Contents/MacOS/ipswitch-cli |
| 特权 helper(嵌入 App) | ipswitch.app/Contents/Library/LaunchServices/ipswitch-helper |