-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathip_test.go
62 lines (57 loc) · 1.15 KB
/
ip_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package realip
import (
"net"
"testing"
)
func TestIP(t *testing.T) {
privateRanges := []Range{
{
Start: net.ParseIP("10.0.0.0"),
End: net.ParseIP("10.255.255.255"),
},
{
Start: net.ParseIP("100.64.0.0"),
End: net.ParseIP("100.127.255.255"),
},
{
Start: net.ParseIP("172.16.0.0"),
End: net.ParseIP("172.31.255.255"),
},
{
Start: net.ParseIP("192.0.0.0"),
End: net.ParseIP("192.0.0.255"),
},
{
Start: net.ParseIP("192.168.0.0"),
End: net.ParseIP("192.168.255.255"),
},
{
Start: net.ParseIP("198.18.0.0"),
End: net.ParseIP("198.19.255.255"),
},
}
addresses := []string{
"201.37.138.59",
"159.117.3.153",
"166.192.97.84",
"225.181.213.210",
"124.50.84.134",
"87.53.250.102",
"106.79.33.62",
"242.120.17.144",
"131.179.101.254",
"103.11.11.174",
"115.97.0.114",
"219.202.120.251",
"37.72.123.120",
"154.94.78.101",
"126.105.144.250",
}
got, ok := GetIPAddress(addresses, privateRanges)
if !ok {
t.Logf("expected addr to be matched")
}
if expected := "126.105.144.250"; expected != got {
t.Logf("expected addr to be found: %s but got: %s", expected, got)
}
}