fix: check local ip for 123pan

pull/761/head
Xhofe 2022-03-15 14:48:39 +08:00
parent 5a1b16a601
commit ef19e851e3
2 changed files with 29 additions and 1 deletions

View File

@ -140,7 +140,7 @@ func (driver Pan123) Link(args base.Args, account *model.Account) (*base.Link, e
}
var resp Pan123DownResp
var headers map[string]string
if args.IP != "" && args.IP != "::1" {
if !utils.IsLocalIPAddr(args.IP) {
headers = map[string]string{
//"X-Real-IP": "1.1.1.1",
"X-Forwarded-For": args.IP,

28
utils/check.go Normal file
View File

@ -0,0 +1,28 @@
package utils
import (
"net"
)
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
}