|
|
@ -5,36 +5,40 @@ import ( |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func TestPrivateIP(t *testing.T) { |
|
|
|
func TestValidIP(t *testing.T) { |
|
|
|
tests := []struct { |
|
|
|
tests := []struct { |
|
|
|
addr string |
|
|
|
addr string |
|
|
|
expect bool |
|
|
|
expect bool |
|
|
|
}{ |
|
|
|
}{ |
|
|
|
|
|
|
|
{"127.0.0.1", false}, |
|
|
|
|
|
|
|
{"255.255.255.255", false}, |
|
|
|
|
|
|
|
{"0.0.0.0", false}, |
|
|
|
|
|
|
|
{"localhost", false}, |
|
|
|
{"10.1.0.1", true}, |
|
|
|
{"10.1.0.1", true}, |
|
|
|
{"172.16.0.1", true}, |
|
|
|
{"172.16.0.1", true}, |
|
|
|
{"192.168.1.1", true}, |
|
|
|
{"192.168.1.1", true}, |
|
|
|
{"8.8.8.8", false}, |
|
|
|
{"8.8.8.8", true}, |
|
|
|
{"1.1.1.1", false}, |
|
|
|
{"1.1.1.1", true}, |
|
|
|
{"9.255.255.255", false}, |
|
|
|
{"9.255.255.255", true}, |
|
|
|
{"10.0.0.0", true}, |
|
|
|
{"10.0.0.0", true}, |
|
|
|
{"10.255.255.255", true}, |
|
|
|
{"10.255.255.255", true}, |
|
|
|
{"11.0.0.0", false}, |
|
|
|
{"11.0.0.0", true}, |
|
|
|
{"172.15.255.255", false}, |
|
|
|
{"172.15.255.255", true}, |
|
|
|
{"172.16.0.0", true}, |
|
|
|
{"172.16.0.0", true}, |
|
|
|
{"172.16.255.255", true}, |
|
|
|
{"172.16.255.255", true}, |
|
|
|
{"172.23.18.255", true}, |
|
|
|
{"172.23.18.255", true}, |
|
|
|
{"172.31.255.255", true}, |
|
|
|
{"172.31.255.255", true}, |
|
|
|
{"172.31.0.0", true}, |
|
|
|
{"172.31.0.0", true}, |
|
|
|
{"172.32.0.0", false}, |
|
|
|
{"172.32.0.0", true}, |
|
|
|
{"192.167.255.255", false}, |
|
|
|
{"192.167.255.255", true}, |
|
|
|
{"192.168.0.0", true}, |
|
|
|
{"192.168.0.0", true}, |
|
|
|
{"192.168.255.255", true}, |
|
|
|
{"192.168.255.255", true}, |
|
|
|
{"192.169.0.0", false}, |
|
|
|
{"192.169.0.0", true}, |
|
|
|
{"fbff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", false}, |
|
|
|
{"fbff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", true}, |
|
|
|
{"fc00::", true}, |
|
|
|
{"fc00::", true}, |
|
|
|
{"fcff:1200:0:44::", true}, |
|
|
|
{"fcff:1200:0:44::", true}, |
|
|
|
{"fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", true}, |
|
|
|
{"fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", true}, |
|
|
|
{"fe00::", false}, |
|
|
|
{"fe00::", true}, |
|
|
|
} |
|
|
|
} |
|
|
|
for _, test := range tests { |
|
|
|
for _, test := range tests { |
|
|
|
t.Run(test.addr, func(t *testing.T) { |
|
|
|
t.Run(test.addr, func(t *testing.T) { |
|
|
|