Documentation
¶
Index ¶
- Constants
- Variables
- func GetDefaultIPs() map[string][]string
- func IsPingAvailable() bool
- func ScoreIP(entry *IPEntry) float64
- func SelectBestIPs(entries []IPEntry, backupCount int) (best *IPEntry, backups []IPEntry)
- type DetectResult
- type Detector
- type DomainIPs
- type HTTPHostsSource
- type HTTPSCheckResult
- type HTTPSChecker
- type IPEntry
- type MultiSource
- type PingResult
- type Pinger
- type Source
- type TCPCheckResult
- type TCPChecker
Constants ¶
const ( GitHub520URL = "https://raw.hellogithub.com/hosts" Ineo6URL = "https://gitlab.com/ineo6/hosts/-/raw/master/hosts" )
数据源 URL
Variables ¶
var DefaultIPs = map[string][]string{
"github.com": {
"20.205.243.166",
"140.82.112.4",
"140.82.114.4",
},
"alive.github.com": {
"140.82.113.25",
},
"live.github.com": {
"140.82.113.25",
},
"ssh.github.com": {
"140.82.112.35",
"140.82.113.35",
},
"gist.github.com": {
"20.205.243.166",
},
"raw.githubusercontent.com": {
"185.199.110.133",
"185.199.108.133",
},
"api.github.com": {
"20.205.243.168",
"140.82.112.5",
},
"codeload.github.com": {
"20.205.243.165",
"140.82.112.10",
},
"avatars.githubusercontent.com": {
"185.199.110.133",
},
"github.githubassets.com": {
"185.199.111.154",
},
"objects.githubusercontent.com": {
"185.199.110.133",
},
"media.githubusercontent.com": {
"185.199.110.133",
},
"user-images.githubusercontent.com": {
"185.199.110.133",
},
"github-cloud.s3.amazonaws.com": {
"16.15.183.87",
},
}
DefaultIPs 内置的兜底 IP 列表 当所有数据源均不可达时使用这份列表 注意:这些 IP 可能会过时,仅作为应急兜底
var TargetDomains = []string{
"github.com",
"alive.github.com",
"live.github.com",
"ssh.github.com",
"gist.github.com",
"raw.githubusercontent.com",
"api.github.com",
"codeload.github.com",
"avatars.githubusercontent.com",
"github.githubassets.com",
"objects.githubusercontent.com",
"media.githubusercontent.com",
"user-images.githubusercontent.com",
"github-cloud.s3.amazonaws.com",
"collector.github.com",
}
TargetDomains 维护的目标 GitHub 域名清单
Functions ¶
Types ¶
type DetectResult ¶
type DetectResult struct {
Domains map[string]*DomainIPs `json:"domains"`
Timestamp int64 `json:"timestamp"`
ICMPUsed bool `json:"icmp_used"` // 是否使用了 ICMP 检测
HTTPSUsed bool `json:"https_used"` // 是否使用了 HTTPS 验证
}
DetectResult 表示一次完整检测的结果
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector 是统一的 IP 检测器,协调数据源获取、多维度检测、评分筛选
type DomainIPs ¶
type DomainIPs struct {
Domain string `json:"domain"`
IPs []IPEntry `json:"ips"`
BestIP *IPEntry `json:"best_ip,omitempty"` // 最优 IP
}
DomainIPs 表示一个域名对应的多个候选 IP
type HTTPHostsSource ¶
type HTTPHostsSource struct {
// contains filtered or unexported fields
}
HTTPHostsSource 从 hosts 文本源获取候选 IP
func NewGitHub520Source ¶
func NewGitHub520Source() *HTTPHostsSource
NewGitHub520Source 创建 GitHub520 数据源
func NewHTTPHostsSource ¶
func NewHTTPHostsSource(name, url string) *HTTPHostsSource
NewHTTPHostsSource 创建通用 hosts 数据源
func (*HTTPHostsSource) Name ¶
func (s *HTTPHostsSource) Name() string
type HTTPSCheckResult ¶
type HTTPSCheckResult struct {
IP string
Domain string
OK bool // 最终 HTTPS 验证是否成功
BasicOK bool // 基础 HTTPS 是否成功(TLS 握手 + HTTP 响应)
BrowserOK bool // 浏览器导向验证是否成功(仅对 github.com 严格要求)
BrowserReason string // 浏览器导向验证结果说明
Port443OK bool // TCP 443 是否已建立连接(即便后续 TLS/HTTP 失败也会保留)
ConnectLatency float64 // TCP 443 建连延迟(毫秒)
Latency float64 // HTTPS 完整延迟(毫秒),包含 TCP 建连 + TLS 握手 + HTTP 首包往返
StatusCode int
BodyBytes int64
Error error
}
HTTPSCheckResult 表示一次 HTTPS 验证结果
type HTTPSChecker ¶
type HTTPSChecker struct {
// contains filtered or unexported fields
}
HTTPSChecker HTTPS 应用层验证器 通过真正的 HTTPS 请求(含 TLS 证书校验)验证候选 IP 的实际可用性
func NewHTTPSChecker ¶
func NewHTTPSChecker(timeout time.Duration) *HTTPSChecker
NewHTTPSChecker 创建 HTTPS 验证器
func NewHTTPSCheckerWithConcurrency ¶
func NewHTTPSCheckerWithConcurrency(timeout time.Duration, concurrency int) *HTTPSChecker
NewHTTPSCheckerWithConcurrency 创建带并发限制的 HTTPS 验证器
func (*HTTPSChecker) Check ¶
func (c *HTTPSChecker) Check(ctx context.Context, ip, domain string) HTTPSCheckResult
Check 对指定 IP 执行 HTTPS 验证 流程:TCP 443 建连 → TLS 握手(验证证书匹配目标域名) → HTTP GET 请求 → 先看响应头,再按需读取少量正文校验页面特征
func (*HTTPSChecker) CheckIPs ¶
func (c *HTTPSChecker) CheckIPs(ctx context.Context, ips []string, domain string) []HTTPSCheckResult
CheckIPs 并发对多个 IP 执行 HTTPS 验证
type IPEntry ¶
type IPEntry struct {
IP string `json:"ip"`
Domain string `json:"domain"`
Latency float64 `json:"latency_ms"` // 延迟(毫秒)
LossRate float64 `json:"loss_rate"` // 丢包率(0.0-1.0)
Port443 bool `json:"port_443"` // TCP 443 端口是否连通
Port22 bool `json:"port_22"` // TCP 22 端口是否连通
BasicHTTPS bool `json:"basic_https"` // 基础 HTTPS 是否通过(TLS 握手 + HTTP 响应)
HTTPS bool `json:"https"` // 最终 HTTPS 验证是否通过(github.com 需满足浏览器导向校验)
HTTPSLatency float64 `json:"https_latency_ms"` // HTTPS 验证延迟(毫秒)
HTTPSStatusCode int `json:"https_status_code"` // HTTPS 响应状态码
BrowserOK bool `json:"browser_ok"` // 浏览器导向验证是否通过(仅 github.com 严格要求)
BrowserReason string `json:"browser_reason,omitempty"`
Score float64 `json:"score"` // 质量评分(0-100)
Available bool `json:"available"` // 是否可用
}
IPEntry 表示一个 IP 检测结果
func FallbackIP ¶
FallbackIP 在主 IP 失效时切换到备选 IP 传入当前域名的检测结果,返回可用的备选 IP 对 github.com 域名:没有可用候选时返回 nil,避免写入不可用 IP 导致退化
type MultiSource ¶
type MultiSource struct {
// contains filtered or unexported fields
}
MultiSource 多数据源聚合,支持汇总多个成功结果
func (*MultiSource) Name ¶
func (m *MultiSource) Name() string
type PingResult ¶
type PingResult struct {
IP string
Latency float64 // 平均延迟(毫秒)
LossRate float64 // 丢包率(0.0-1.0)
OK bool // 是否成功
Error error
}
PingResult 表示一次 ping 检测结果
type Pinger ¶
type Pinger struct {
// contains filtered or unexported fields
}
Pinger 通过系统 ping 命令检测 IP 可达性
type Source ¶
type Source interface {
// FetchIPs 获取域名-IP 映射列表
FetchIPs(ctx context.Context) (map[string][]string, error)
// Name 返回数据源名称
Name() string
}
Source 定义数据源接口
type TCPCheckResult ¶
TCPCheckResult 表示一次 TCP 端口检测结果
type TCPChecker ¶
type TCPChecker struct {
// contains filtered or unexported fields
}
TCPChecker TCP 端口检测器
func NewTCPChecker ¶
func NewTCPChecker(timeout time.Duration) *TCPChecker
NewTCPChecker 创建 TCP 端口检测器
func (*TCPChecker) CheckIPPorts ¶
func (c *TCPChecker) CheckIPPorts(ctx context.Context, ips []string, ports []int) map[string][]TCPCheckResult
CheckIPPorts 对多个 IP 并发检测指定端口列表
func (*TCPChecker) CheckPort ¶
func (c *TCPChecker) CheckPort(ctx context.Context, ip string, port int) TCPCheckResult
CheckPort 检测指定 IP 的 TCP 端口是否可连通
func (*TCPChecker) CheckPorts ¶
func (c *TCPChecker) CheckPorts(ctx context.Context, ip string, ports []int) []TCPCheckResult
CheckPorts 并发检测指定 IP 的多个 TCP 端口