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

Function NextIP

utils.go:45–66  ·  view source on GitHub ↗

NextIP 获取下一个或上一个IP地址

(ip net.IP, increment bool)

Source from the content-addressed store, hash-verified

43
44// NextIP 获取下一个或上一个IP地址
45func NextIP(ip net.IP, increment bool) net.IP {
46 // 将IP转换为大整数
47 ipb := big.NewInt(0).SetBytes(ip)
48
49 if increment {
50 ipb.Add(ipb, big.NewInt(1))
51 } else {
52 ipb.Sub(ipb, big.NewInt(1))
53 }
54
55 // 转换回IP格式
56 b := ipb.Bytes()
57
58 // 确保字节长度正确
59 if len(ip) == 4 { // IPv4
60 b = append(make([]byte, 4-len(b)), b...)
61 } else { // IPv6
62 b = append(make([]byte, 16-len(b)), b...)
63 }
64
65 return net.IP(b)
66}
67
68// ParseHost 解析主机字符串,返回Host结构体
69func ParseHost(hostStr string) (Host, error) {

Callers 3

expandCIDRFunction · 0.85
IterateAddrFunction · 0.85
IterateCIDRFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected