IsPrivateIP 检查IP是否为私有地址
(ip net.IP)
| 413 | |
| 414 | // IsPrivateIP 检查IP是否为私有地址 |
| 415 | func 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文件 |
| 428 | func DownloadGeoLite2DB(filePath string) error { |
nothing calls this directly
no outgoing calls
no test coverage detected