Documentation
¶
Index ¶
- Constants
- Variables
- func AddrIP(a net.Addr) net.IP
- func Aliyun() *net.Resolver
- func AllowCrossOriginBrowserAccess() bool
- func Cloudflare() *net.Resolver
- func DNSSB() *net.Resolver
- func Dnspod() *net.Resolver
- func DomainLookUp(host string, ipVersion string, dotServer string, disableOutput bool) (net.IP, error)
- func DomainLookUpWithContext(ctx context.Context, host string, ipVersion string, dotServer string, ...) (net.IP, error)
- func FudgeWordForSeq(S0, targetChecksum uint16) uint16
- func GetEnvBool(key string, def bool) bool
- func GetEnvDefault(key string, def string) string
- func GetEnvInt(key string, def int) int
- func GetEnvTrimmed(key string) (string, bool)
- func GetFastIP(domain string, port string, enableOutput bool) string
- func GetFastIPCache() string
- func GetFastIPWithContext(ctx context.Context, domain string, port string, enableOutput bool) (string, error)
- func GetHostAndPort() (host string, port string)
- func GetICMPID(data []byte) (int, error)
- func GetICMPResponsePayload(data []byte) ([]byte, error)
- func GetICMPSeq(data []byte) (int, error)
- func GetIPHeaderLength(data []byte) (int, error)
- func GetMTUByIP(srcIP net.IP) int
- func GetMTUByIPForDevice(srcIP net.IP, srcDev string) int
- func GetPowProvider() string
- func GetProxy() *url.URL
- func GetTCPPorts(data []byte) (int, int, error)
- func GetTCPSeq(data []byte) (int, error)
- func GetUDPPorts(data []byte) (int, int, error)
- func GetUDPSeq(data []byte) (int, error)
- func GetUDPSeqv6(data []byte) (int, error)
- func Google() *net.Resolver
- func HasAdminPrivileges() bool
- func HideIPPart(ip string) string
- func IsIPv6(ip net.IP) bool
- func LocalIPPort(dstIP net.IP, srcIP net.IP, proto string) (net.IP, int)
- func LocalIPPortv6(dstIP net.IP, srcIP net.IP, proto string) (net.IP, int)
- func LookupAddr(addr string) ([]string, error)
- func LookupAddrWithContext(ctx context.Context, addr string) ([]string, error)
- func LookupHostForGeo(ctx context.Context, host string) ([]net.IP, error)
- func MakePayloadWithTargetChecksum(payload []byte, srcIP, dstIP net.IP, srcPort, dstPort int, ...) error
- func NewGeoHTTPClient(timeout time.Duration) *http.Client
- func RandomPortEnabled() bool
- func ReadStdinLine(ctx context.Context) (string, error)
- func ResolverForDot(dotServer string) *net.Resolver
- func SetFastIPCacheState(ip string, meta FastIPMeta)
- func SetGeoDNSFallback(enabled bool)
- func SetGeoDNSResolver(dotServer string)
- func StringInSlice(val string, list []string) bool
- func UDPBaseSum(srcIP, dstIP net.IP, srcPort, dstPort, udpLen int, payload []byte) uint16
- func WithGeoDNSResolver[T any](dotServer string, callback func() (T, error)) (T, error)
- type FastIPMeta
- type IPv4Fragment
- type ResponseInfo
- type TracePrivilegeCheck
Constants ¶
const EnvAllowCrossOriginKey = "NEXTTRACE_ALLOW_CROSS_ORIGIN"
Variables ¶
var ( DisableMPLS = GetEnvBool("NEXTTRACE_DISABLEMPLS", false) EnableHidDstIP = GetEnvBool("NEXTTRACE_ENABLEHIDDENDSTIP", false) EnvDevMode = GetEnvBool("NEXTTRACE_DEVMODE", false) EnvRandomPort = GetEnvBool("NEXTTRACE_RANDOMPORT", false) Uninterrupted = GetEnvBool("NEXTTRACE_UNINTERRUPTED", false) EnvProxyURL = GetEnvDefault("NEXTTRACE_PROXY", "") EnvToken = GetEnvDefault("NEXTTRACE_TOKEN", "") EnvDataProvider = GetEnvDefault("NEXTTRACE_DATAPROVIDER", "") EnvHostPort = GetEnvDefault("NEXTTRACE_HOSTPORT", "api.nxtrace.org") EnvPowProvider = GetEnvDefault("NEXTTRACE_POWPROVIDER", "api.nxtrace.org") EnvDeployAddr = GetEnvDefault("NEXTTRACE_DEPLOY_ADDR", "") EnvDeployToken = GetEnvDefault("NEXTTRACE_DEPLOY_TOKEN", "") EnvMaxAttempts = GetEnvInt("NEXTTRACE_MAXATTEMPTS", 0) EnvICMPMode = GetEnvInt("NEXTTRACE_ICMPMODE", 0) GlobalpingToken = GetEnvDefault("GLOBALPING_TOKEN", "") )
var DstIP string
var FastIpCache = ""
var PowProviderParam = ""
var SrcDev string
var SrcPort int
var SuppressFastIPOutput bool
SuppressFastIPOutput 为 true 时,GetFastIP 即使 enableOutput=true 也不打印彩色输出。 MTR 模式在进入备用屏前设置此标志,避免污染主终端历史。
Functions ¶
func AddrIP ¶ added in v1.5.0
AddrIP 从常见的 net.Addr 中提取 IP:支持 *net.IPNet / *net.IPAddr / *net.TCPAddr / *net.UDPAddr 若无法提取,返回 nil
func AllowCrossOriginBrowserAccess ¶ added in v1.5.2
func AllowCrossOriginBrowserAccess() bool
func Cloudflare ¶
func DomainLookUp ¶
func DomainLookUpWithContext ¶ added in v1.6.1
func FudgeWordForSeq ¶ added in v1.5.0
FudgeWordForSeq 给定 S0 与目标 checksum(如 seq),返回应写入 payload[0:2] 的补偿值(16 位) 原理:最终一补和 targetSum = ^targetChecksum;令补偿位 X,则 X = targetSum ⊕ (~S0)
func GetEnvBool ¶ added in v1.5.0
func GetEnvDefault ¶ added in v1.5.0
func GetEnvTrimmed ¶ added in v1.5.0
func GetFastIPCache ¶ added in v1.6.1
func GetFastIPCache() string
func GetFastIPWithContext ¶ added in v1.6.1
func GetHostAndPort ¶
func GetICMPResponsePayload ¶
func GetICMPSeq ¶ added in v1.5.0
func GetIPHeaderLength ¶
func GetMTUByIP ¶ added in v1.5.0
GetMTUByIP 保持旧调用点兼容,优先使用全局 SrcDev。
func GetMTUByIPForDevice ¶ added in v1.5.2
GetMTUByIPForDevice 根据给定 IPv4/IPv6 源地址返回所属网卡 MTU,优先使用指定网卡名。
func GetPowProvider ¶
func GetPowProvider() string
func GetUDPSeqv6 ¶ added in v1.5.0
func HasAdminPrivileges ¶ added in v1.6.1
func HasAdminPrivileges() bool
func HideIPPart ¶ added in v1.2.6
func LocalIPPort ¶
LocalIPPort 根据目标 IPv4(以及可选的源 IPv4 与协议)返回本地 IP 与一个可用端口
func LocalIPPortv6 ¶
LocalIPPortv6 根据目标 IPv6(以及可选的源 IPv6 与协议)返回本地 IP 与一个可用端口
func LookupAddr ¶
func LookupAddrWithContext ¶ added in v1.6.1
func LookupHostForGeo ¶ added in v1.5.2
LookupHostForGeo 执行"Geo 专用"DNS 查询。
- 如果 host 是 IP 字面量,直接返回,不做 DNS 查询。
- 若配置了 DoT,优先用 DoT 解析。
- DoT 失败且 fallback=true 时,回退系统 DNS。
- 全部失败才返回 error。
func MakePayloadWithTargetChecksum ¶ added in v1.5.0
func MakePayloadWithTargetChecksum(payload []byte, srcIP, dstIP net.IP, srcPort, dstPort int, targetChecksum uint16) error
MakePayloadWithTargetChecksum 修改 payload,使最终 UDP.Checksum == targetChecksum 要求:payload 长度 >= 2(前 2 字节作为补偿位写入)
func NewGeoHTTPClient ¶ added in v1.5.2
NewGeoHTTPClient 返回一个使用 Geo DNS 解析策略的 *http.Client。
内部 Transport.DialContext 会通过 LookupHostForGeo 解析目标 host, 然后按 IP 拨号,保持请求 URL Host 不变(即 TLS SNI 不受影响)。
func RandomPortEnabled ¶ added in v1.5.0
func RandomPortEnabled() bool
func ReadStdinLine ¶ added in v1.6.5
ReadStdinLine reads one line from a process-wide stdin reader.
func ResolverForDot ¶ added in v1.5.2
ResolverForDot 根据 dotServer 名字返回对应的 *net.Resolver。 空 / 未知名字返回 nil(表示"使用系统默认")。
func SetFastIPCacheState ¶ added in v1.6.1
func SetFastIPCacheState(ip string, meta FastIPMeta)
func SetGeoDNSFallback ¶ added in v1.5.2
func SetGeoDNSFallback(enabled bool)
SetGeoDNSFallback 设置 DoT 失败后是否回退系统 DNS,默认 true。
func SetGeoDNSResolver ¶ added in v1.5.2
func SetGeoDNSResolver(dotServer string)
SetGeoDNSResolver 设置 Geo 解析使用的 DoT 服务器名称。 空字符串表示仅使用系统 DNS。
func StringInSlice ¶
func UDPBaseSum ¶ added in v1.5.0
UDPBaseSum 在“UDP.Checksum 视为 0、payload[0:2]=0x0000”的前提下,计算 16 位一补和 S0
Types ¶
type FastIPMeta ¶ added in v1.5.2
type FastIPMeta struct {
IP string // 节点 IP
Latency string // 延迟(ms 字符串)
NodeName string // 节点名称(API 返回的 Content 去除前后空白)
}
FastIPMeta 存储 FastIP 节点的结构化元数据。
var FastIPMetaCache FastIPMeta
FastIPMetaCache 缓存最近一次 FastIP 探测返回的节点元数据。
func GetFastIPMetaCache ¶ added in v1.6.1
func GetFastIPMetaCache() FastIPMeta
type IPv4Fragment ¶ added in v1.5.0
func IPv4Fragmentize ¶ added in v1.5.0
IPv4Fragmentize 将 base(IPv4 头)与 body(IPv4 负载:传输层头+数据)按 mtu 进行 IP 层分片
type ResponseInfo ¶
type TracePrivilegeCheck ¶ added in v1.6.1
func TracePrivilegeStatus ¶ added in v1.6.1
func TracePrivilegeStatus(appBinName string, _ bool) TracePrivilegeCheck