release: v0.2.0
Some checks failed
Release / Build & Release (push) Has been cancelled

Comprehensive release containing structural, UX, and behavioral upgrades since v0.1.0:

1. Namespace Transition: Renamed core executable and project namespaces from 'smart-monitor' to 'smart-shutdown'.
2. Objective Vocabulary Refactoring: Normalized output strings and logging descriptors system-wide to a strict, professional tone.
3. Advanced Status Query: 'status' subcommand now retrieves the parsed configuration, log locations/sizes, and tails the last 10 lines of the local log file.
4. Runtime Configuration Setter: Introduced 'config set' subcommand to modify the configuration file with strict type validations.
5. Auto-System Deployment: Remapped 'install' to clone the executable into system domains and register global PATH variables.
6. Cleaner Removal: 'uninstall' purges binary clones and clears environmental variables, leaving zero traces.
7. Documentation Rewrite: Generated an objective README file featuring copy-paste ready Markdown blocks.
This commit is contained in:
2026-03-24 16:07:22 +08:00
parent 3525a59976
commit 3be3e19e49
10 changed files with 243 additions and 237 deletions

View File

@@ -7,35 +7,28 @@ import (
"smart-shutdown/pkg/logger"
)
// Ping 连通性测试,向指定的 targetIP 发送 ICMP 请求。
// 如果规定时间内可达返回 true超时或者全部丢包返回 false。
func Ping(targetIP string, timeoutSec int) bool {
pinger, err := probing.NewPinger(targetIP)
if err != nil {
logger.Warn("解析目标 IP 失败 [%s]: %v", targetIP, err)
logger.Warn("目标 IP 解析异常 [%s]: %v", targetIP, err)
return false
}
// 大部分操作系统为了安全,普通程序发 ICMP 包会被拦截。开启 Privileged 会尝试使用 raw sockets 发行
// 本程序由于本身作为系统服务System 或 Root 权限)运行,故直接开启特权模式以保障发包成功率。
pinger.SetPrivileged(true)
// 只发送 1 个探测包
pinger.Count = 1
pinger.Timeout = time.Duration(timeoutSec) * time.Second
err = pinger.Run()
if err != nil {
logger.Fail("Ping 测试运行时遇到异常: %v", err)
logger.Fail("探针执行失败: %v", err)
return false
}
stats := pinger.Statistics()
// 只要成功收到至少 1 个回包,认为网络通畅
if stats.PacketsRecv > 0 {
return true
}
// 丢包或者无回音
return false
}