mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
split host port
This commit is contained in:
parent
16fef9e9f7
commit
e145f6c61a
2 changed files with 6 additions and 1 deletions
|
@ -278,7 +278,8 @@ var PrivateIPNetworks = []net.IPNet{
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsLocalIP(ipaddress string) bool {
|
func IsLocalIP(ipaddress string) bool {
|
||||||
ip := net.ParseIP(ipaddress)
|
host, _, _ := net.SplitHostPort(ipaddress)
|
||||||
|
ip := net.ParseIP(host)
|
||||||
for _, ipNet := range PrivateIPNetworks {
|
for _, ipNet := range PrivateIPNetworks {
|
||||||
if ipNet.Contains(ip) {
|
if ipNet.Contains(ip) {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -191,3 +191,7 @@ func TestFindOpenPorts(t *testing.T) {
|
||||||
openPorts := FindOpenPorts("localhost", 9009, 4)
|
openPorts := FindOpenPorts("localhost", 9009, 4)
|
||||||
assert.Equal(t, []int{9009, 9010, 9011, 9012}, openPorts)
|
assert.Equal(t, []int{9009, 9010, 9011, 9012}, openPorts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsLocalIP(t *testing.T) {
|
||||||
|
assert.True(t, IsLocalIP("192.168.0.14:9009"))
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue