diff --git a/src/utils/utils.go b/src/utils/utils.go index a393c792..e226b9be 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -278,7 +278,8 @@ var PrivateIPNetworks = []net.IPNet{ } func IsLocalIP(ipaddress string) bool { - ip := net.ParseIP(ipaddress) + host, _, _ := net.SplitHostPort(ipaddress) + ip := net.ParseIP(host) for _, ipNet := range PrivateIPNetworks { if ipNet.Contains(ip) { return true diff --git a/src/utils/utils_test.go b/src/utils/utils_test.go index cd7bd8cc..101162e5 100644 --- a/src/utils/utils_test.go +++ b/src/utils/utils_test.go @@ -191,3 +191,7 @@ func TestFindOpenPorts(t *testing.T) { openPorts := FindOpenPorts("localhost", 9009, 4) assert.Equal(t, []int{9009, 9010, 9011, 9012}, openPorts) } + +func TestIsLocalIP(t *testing.T) { + assert.True(t, IsLocalIP("192.168.0.14:9009")) +}