MCPcopy Create free account
hub / github.com/MengMengCode/GetRealityDomain / IsPrivateIP

Function IsPrivateIP

utils.go:415–425  ·  view source on GitHub ↗

IsPrivateIP 检查IP是否为私有地址

(ip net.IP)

Source from the content-addressed store, hash-verified

413
414// IsPrivateIP 检查IP是否为私有地址
415func IsPrivateIP(ip net.IP) bool {
416 if ip4 := ip.To4(); ip4 != nil {
417 // IPv4私有地址范围
418 return ip4[0] == 10 ||
419 (ip4[0] == 172 && ip4[1] >= 16 && ip4[1] <= 31) ||
420 (ip4[0] == 192 && ip4[1] == 168)
421 }
422
423 // IPv6私有地址检查
424 return len(ip) == 16 && ip[0] == 0xfc || ip[0] == 0xfd
425}
426
427// DownloadGeoLite2DB 下载GeoLite2-Country.mmdb文件
428func DownloadGeoLite2DB(filePath string) error {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected