MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / IsLocalIP

Function IsLocalIP

internal/utils/ip.go:9–33  ·  view source on GitHub ↗

IsLocalIP 判断是否为本地IP

(ipString string)

Source from the content-addressed store, hash-verified

7
8// IsLocalIP 判断是否为本地IP
9func IsLocalIP(ipString string) bool {
10 var ip = net.ParseIP(ipString)
11 if ip == nil {
12 return false
13 }
14
15 // IPv6
16 if strings.Contains(ipString, ":") {
17 return ip.String() == "::1"
18 }
19
20 // IPv4
21 ip = ip.To4()
22 if ip == nil {
23 return false
24 }
25 if ip[0] == 127 ||
26 ip[0] == 10 ||
27 (ip[0] == 172 && ip[1]&0xf0 == 16) ||
28 (ip[0] == 192 && ip[1] == 168) {
29 return true
30 }
31
32 return false
33}
34
35// IsIPv4 是否为IPv4
36func IsIPv4(ip string) bool {

Callers 5

TestIsLocalIPFunction · 0.92
ReadMethod · 0.92
increaseSYNFloodMethod · 0.92
MatchRequestMethod · 0.92
LoopMethod · 0.92

Calls 3

ParseIPMethod · 0.80
ContainsMethod · 0.45
StringMethod · 0.45

Tested by 1

TestIsLocalIPFunction · 0.74