From e145f6c61a532b0ed2a7b766fc9bf60784a0f247 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 5 Oct 2020 08:16:34 -0700 Subject: [PATCH] split host port --- src/utils/utils.go | 3 ++- src/utils/utils_test.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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")) +}