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.
35 lines
611 B
Go
35 lines
611 B
Go
package pinger
|
|
|
|
import (
|
|
"time"
|
|
|
|
probing "github.com/prometheus-community/pro-bing"
|
|
"smart-shutdown/pkg/logger"
|
|
)
|
|
|
|
func Ping(targetIP string, timeoutSec int) bool {
|
|
pinger, err := probing.NewPinger(targetIP)
|
|
if err != nil {
|
|
logger.Warn("目标 IP 解析异常 [%s]: %v", targetIP, err)
|
|
return false
|
|
}
|
|
|
|
pinger.SetPrivileged(true)
|
|
|
|
pinger.Count = 1
|
|
pinger.Timeout = time.Duration(timeoutSec) * time.Second
|
|
|
|
err = pinger.Run()
|
|
if err != nil {
|
|
logger.Fail("探针执行失败: %v", err)
|
|
return false
|
|
}
|
|
|
|
stats := pinger.Statistics()
|
|
if stats.PacketsRecv > 0 {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|