nettools

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nettools 提供网络诊断工具:Ping、Traceroute、TCP 端口探测、DNS 查询、测速与局域网扫描。 工具以后台任务运行,接口立即返回任务 ID,界面轮询输出。

Index

Constants

View Source
const (
	ToolPing       = "ping"
	ToolTraceroute = "traceroute"
	ToolTCP        = "tcp"
	ToolDNS        = "dns"
	ToolSpeed      = "speed"
	ToolScan       = "scan"
)

工具名称

View Source
const ID = "nettools"

ID 是模块标识。

Variables

This section is empty.

Functions

func ParsePorts

func ParsePorts(s string) ([]int, error)

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 Module

type Module struct {
	// contains filtered or unexported fields
}

Module 是网络诊断模块。

func New

func New() *Module

New 创建模块。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) Init

func (m *Module) Init(env module.Env) error

Init 实现 module.Module。

func (*Module) Routes

func (m *Module) Routes(r module.Router)

Routes 实现 module.Module。

func (*Module) Start

func (m *Module) Start(context.Context) error

Start 实现 module.Module。

func (*Module) Stop

func (m *Module) Stop() error

Stop 实现 module.Module:取消所有运行中的任务。

func (*Module) Title

func (m *Module) Title() string

Title 实现 module.Module。

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 是一次工具运行。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL