Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from hossinasaadi/limit-connection
Browse files Browse the repository at this point in the history
fix getting server IP
  • Loading branch information
hossinasaadi authored Nov 5, 2022
2 parents 7327f26 + 675c211 commit 5e2c12b
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions web/job/check_clinet_ip_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,39 +277,15 @@ 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)

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){

Expand Down

0 comments on commit 5e2c12b

Please sign in to comment.