From 16fef9e9f716edb5fd09e5f486d12f82161984c0 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 5 Oct 2020 08:12:30 -0700 Subject: [PATCH] don't proxy local connectoins --- src/comm/comm.go | 3 ++- src/utils/utils.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/comm/comm.go b/src/comm/comm.go index af617e83..7afa12d8 100644 --- a/src/comm/comm.go +++ b/src/comm/comm.go @@ -8,6 +8,7 @@ import ( "net" "time" + "github.com/schollz/croc/v8/src/utils" log "github.com/schollz/logger" "golang.org/x/net/proxy" ) @@ -28,7 +29,7 @@ func NewConnection(address string, timelimit ...time.Duration) (c *Comm, err err tlimit = timelimit[0] } var connection net.Conn - if Socks5Proxy != "" { + if Socks5Proxy != "" && !utils.IsLocalIP(address) { var dialer proxy.Dialer dialer, err = proxy.SOCKS5("tcp", Socks5Proxy, nil, proxy.Direct) if err != nil { diff --git a/src/utils/utils.go b/src/utils/utils.go index 8a0224bd..a393c792 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -261,3 +261,28 @@ func FindOpenPorts(host string, portNumStart, numPorts int) (openPorts []int) { } return } + +var PrivateIPNetworks = []net.IPNet{ + net.IPNet{ + IP: net.ParseIP("10.0.0.0"), + Mask: net.CIDRMask(8, 32), + }, + net.IPNet{ + IP: net.ParseIP("172.16.0.0"), + Mask: net.CIDRMask(12, 32), + }, + net.IPNet{ + IP: net.ParseIP("192.168.0.0"), + Mask: net.CIDRMask(16, 32), + }, +} + +func IsLocalIP(ipaddress string) bool { + ip := net.ParseIP(ipaddress) + for _, ipNet := range PrivateIPNetworks { + if ipNet.Contains(ip) { + return true + } + } + return false +}