Documentation
¶
Overview ¶
Package nettools 提供网络诊断工具:Ping、Traceroute、TCP 端口探测、DNS 查询、测速与局域网扫描。 工具以后台任务运行,接口立即返回任务 ID,界面轮询输出。
Index ¶
Constants ¶
const ( ToolPing = "ping" ToolTraceroute = "traceroute" ToolTCP = "tcp" ToolDNS = "dns" ToolSpeed = "speed" ToolScan = "scan" )
工具名称
const ID = "nettools"
ID 是模块标识。
Variables ¶
This section is empty.
Functions ¶
func ParsePorts ¶
ParsePorts 解析 "22,80,8000-8100",最多返回 1024 个端口。
Types ¶
type Host ¶
type Host struct {
IP string `json:"ip"`
MAC string `json:"mac,omitempty"`
Hostname string `json:"hostname,omitempty"`
Ports []int `json:"ports,omitempty"`
RTTms int64 `json:"rttMs"`
}
Host 是局域网扫描发现的设备。
type PortResult ¶
type PortResult struct {
Port int `json:"port"`
Open bool `json:"open"`
RTTms int64 `json:"rttMs,omitempty"`
Service string `json:"service,omitempty"`
}
PortResult 是端口探测结果。
type Request ¶
type Request struct {
Tool string `json:"tool"`
// Target 为主机名或 IP(ping / traceroute / tcp / dns 的查询名 / speed 不使用)
Target string `json:"target"`
// Count 为 ping 次数,默认 4,最多 20
Count int `json:"count"`
// Ports 为 tcp 探测端口,如 "22,80,8000-8100"
Ports string `json:"ports"`
// Type 为 DNS 记录类型:A AAAA CNAME MX TXT NS PTR,默认 A
Type string `json:"type"`
// Server 为 DNS 服务器:223.5.5.5、223.5.5.5:5353、https://dns.alidns.com/dns-query
Server string `json:"server"`
// URL 为测速下载地址,留空使用默认
URL string `json:"url"`
// Seconds 为测速时长,默认 8,最多 30
Seconds int `json:"seconds"`
// CIDR 为局域网扫描网段,留空使用本机主网卡所在网段
CIDR string `json:"cidr"`
}
Request 是运行工具的请求,各工具只使用相关字段。
type Settings ¶
type Settings struct {
// Deny 为禁止探测的 IP / 网段,在默认列表之外追加
Deny []string `json:"deny"`
}
Settings 是模块设置。
type Task ¶
type Task struct {
ID string `json:"id"`
Tool string `json:"tool"`
Title string `json:"title"`
Status string `json:"status"` // running / done / error / canceled
Error string `json:"error,omitempty"`
Lines []string `json:"lines"`
Result any `json:"result,omitempty"`
Started time.Time `json:"started"`
Finished time.Time `json:"finished,omitzero"`
// contains filtered or unexported fields
}
Task 是一次工具运行。