mirror of
https://github.com/alireza0/x-ui.git
synced 2026-03-14 05:23:09 +00:00
fix getting server IP
This commit is contained in:
@@ -277,9 +277,8 @@ func LocalIP() ([]string, error) {
|
||||
ip = v.IP
|
||||
}
|
||||
|
||||
if isPrivateIP(ip) {
|
||||
ips = append(ips,ip.String())
|
||||
}
|
||||
ips = append(ips,ip.String())
|
||||
|
||||
}
|
||||
}
|
||||
logger.Debug("System IPs : ",ips)
|
||||
@@ -287,29 +286,6 @@ func LocalIP() ([]string, error) {
|
||||
return ips, nil
|
||||
}
|
||||
|
||||
func isPrivateIP(ip net.IP) bool {
|
||||
var privateIPBlocks []*net.IPNet
|
||||
for _, cidr := range []string{
|
||||
// don't check loopback ips
|
||||
//"127.0.0.0/8", // IPv4 loopback
|
||||
//"::1/128", // IPv6 loopback
|
||||
//"fe80::/10", // IPv6 link-local
|
||||
"10.0.0.0/8", // RFC1918
|
||||
"172.16.0.0/12", // RFC1918
|
||||
"192.168.0.0/16", // RFC1918
|
||||
} {
|
||||
_, block, _ := net.ParseCIDR(cidr)
|
||||
privateIPBlocks = append(privateIPBlocks, block)
|
||||
}
|
||||
|
||||
for _, block := range privateIPBlocks {
|
||||
if block.Contains(ip) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func IPsToRegex(ips []string) (string){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user