fix(123): pass ip when getting download link

This commit is contained in:
Noah Hsu
2022-09-10 13:54:10 +08:00
parent 220cd4d6b8
commit 5ed43fd17d
2 changed files with 66 additions and 3 deletions

View File

@ -24,3 +24,26 @@ func ClientIP(r *http.Request) string {
return ""
}
func IsLocalIPAddr(ip string) bool {
return IsLocalIP(net.ParseIP(ip))
}
func IsLocalIP(ip net.IP) bool {
if ip == nil {
return false
}
if ip.IsLoopback() {
return true
}
ip4 := ip.To4()
if ip4 == nil {
return false
}
return ip4[0] == 10 || // 10.0.0.0/8
(ip4[0] == 172 && ip4[1] >= 16 && ip4[1] <= 31) || // 172.16.0.0/12
(ip4[0] == 169 && ip4[1] == 254) || // 169.254.0.0/16
(ip4[0] == 192 && ip4[1] == 168) // 192.168.0.0/16
}