MCPcopy Index your code
hub / github.com/MengMengCode/GetRealityDomain / ParseHost

Function ParseHost

utils.go:69–98  ·  view source on GitHub ↗

ParseHost 解析主机字符串,返回Host结构体

(hostStr string)

Source from the content-addressed store, hash-verified

67
68// ParseHost 解析主机字符串,返回Host结构体
69func ParseHost(hostStr string) (Host, error) {
70 hostStr = strings.TrimSpace(hostStr)
71
72 // 尝试解析为IP地址
73 if ip := net.ParseIP(hostStr); ip != nil {
74 return Host{
75 IP: ip,
76 Origin: hostStr,
77 Type: HostTypeIP,
78 }, nil
79 }
80
81 // 尝试解析为CIDR
82 if _, _, err := net.ParseCIDR(hostStr); err == nil {
83 return Host{
84 Origin: hostStr,
85 Type: HostTypeCIDR,
86 }, nil
87 }
88
89 // 尝试解析为域名
90 if ValidateDomainName(hostStr) {
91 return Host{
92 Origin: hostStr,
93 Type: HostTypeDomain,
94 }, nil
95 }
96
97 return Host{}, fmt.Errorf("无法解析主机: %s", hostStr)
98}
99
100// Iterate 从Reader中迭代读取主机信息
101func Iterate(reader io.Reader) <-chan Host {

Callers 2

IterateFunction · 0.85
scanAddressFunction · 0.85

Calls 1

ValidateDomainNameFunction · 0.85

Tested by

no test coverage detected