1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

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" "net"
"time" "time"
"github.com/schollz/croc/v8/src/utils"
log "github.com/schollz/logger" log "github.com/schollz/logger"
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
) )
@ -28,7 +29,7 @@ func NewConnection(address string, timelimit ...time.Duration) (c *Comm, err err
tlimit = timelimit[0] tlimit = timelimit[0]
} }
var connection net.Conn var connection net.Conn
if Socks5Proxy != "" { if Socks5Proxy != "" && !utils.IsLocalIP(address) {
var dialer proxy.Dialer var dialer proxy.Dialer
dialer, err = proxy.SOCKS5("tcp", Socks5Proxy, nil, proxy.Direct) dialer, err = proxy.SOCKS5("tcp", Socks5Proxy, nil, proxy.Direct)
if err != nil { if err != nil {

View file

@ -261,3 +261,28 @@ func FindOpenPorts(host string, portNumStart, numPorts int) (openPorts []int) {
} }
return 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
}