don't proxy local connectoins

This commit is contained in:
Zack Scholl 2020-10-05 08:12:30 -07:00
parent ceb68ce670
commit 16fef9e9f7
2 changed files with 27 additions and 1 deletions

View File

@ -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 {

View File

@ -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
}