scanner

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CancelScan  context.CancelFunc
	Conf        ScanConfig
	Status      ScanStatus
	StatusMutex sync.Mutex
)

定义全局变量

Functions

func ListenForStopKey

func ListenForStopKey(ctx context.Context, cancel context.CancelFunc, done chan struct{})

func TestSpeed

func TestSpeed(parentCtx context.Context, ip string, domain string, timeout time.Duration, l Logger) (float64, error)

TestSpeed 对指定 IP 进行下载测速

Types

type FinalResult

type FinalResult struct {
	IP          string  `json:"address"`
	Latency     string  `json:"-"` // 用于展示和 CSV 的字符串
	DownloadMBs float64 `json:"-"` // 下载速度
	RawLatency  int64   `json:"-"` // 内部排序用的数值 (ms)

	CreatedAt time.Time `json:"-"` // 记录测试时间
	// contains filtered or unexported fields
}

结构体定义,用于 JSON 和 CSV 导出

func RunDeepTest

func RunDeepTest(ctx context.Context, outCount int, domain string, minSpeed float64, finalResults []FinalResult, l Logger) []FinalResult

启动测速

func RunScanPool

func RunScanPool(ctx context.Context, ipGroups [][]string, workerCount int, domain string, latency int64, total int, l Logger) []FinalResult

RunScanPool 启动并发扫描

func ScanIP

func ScanIP(ctx context.Context, ip string, domain string, timeout time.Duration, latency int64) FinalResult

ScanIP 对指定 IP 进行探测

type Logger

type Logger interface {
	WriteLog(string)
	GetTheme() progressbar.Theme // 获取进度条主题
	GetColorCodes() bool
}

Logger 定义了扫描器需要的日志能力 只要任何类型实现了这个 WriteLog 方法,就可以传给扫描器

type ScanConfig

type ScanConfig struct {
	NThreads   int     `json:"nthreads"`    // 并发协程数
	MinLatency int64   `json:"min_latency"` // 最小延迟
	FinalCount int     `json:"final_count"` // 最终结果保留的数
	MinSpeed   float64 `json:"min_speed"`   // 最小下载速度
	TestNum    int     `json:"test_num"`    // 每段 IP 抽样数
	FilePath   string  `json:"file_path"`   // IP 来源文件路径
	SniDomain  string  `json:"sni_domain"`  // 测试的地址
	OutPrefix  string  `json:"out_prefix"`  // 输出文件的前缀
	JsonPath   string  `json:"json_path"`   // 追加文件的路径
	AppendMode bool    `json:"append_mode"` // 是否启用追加
	ShowVer    bool    `json:"show_ver"`    // 是否显示版本
	ShowWeb    bool    `json:"show_web"`    // 是否启用 web GUI
	ShouldRun  bool    `json:"should_run"`  // 运行扫描
	DownloadV5 bool    // 是否下载 v5-result
}

func (*ScanConfig) Check

func (conf *ScanConfig) Check()

检查扫描参数,防止不合理设置

type ScanStatus

type ScanStatus struct {
	IsRunning bool `json:"is_running"`
	WaitStop  bool
}

type SpeedResult

type SpeedResult struct {
	IP    string
	Speed float64 // 单位: MB/s
}

SpeedResult 存储测速结果

type WSMessage

type WSMessage struct {
	Type string `json:"type"` // "log" 或 "status"
	Data any    `json:"data"` // 日志内容 或 状态对象
}

定义发送给前端的消息结构

Jump to

Keyboard shortcuts

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