Skip to content

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhjaxt authored Jan 29, 2024
1 parent 7ff7a31 commit a2a1569
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,32 @@ import (
"flag"
"log"
"net"
"io"
"time"

"h12.io/socks"
)

var lAddr = flag.String(`l`, `127.0.0.1:3388`, `Listen address`)
var socksURI = flag.String(`x`, `socks5://127.0.0.1:1080?timeout=5m`, `Socks URI`)
var socksURI = flag.String(`x`, `socks5://127.0.0.1:1080?timeout=15m`, `Socks URI`)
var proxyAddr = flag.String(`r`, `10.10.10.10:3389`, `Remote address`)
var dialFunc func(string, string) (net.Conn, error)

func copy2(dst net.Conn, src net.Conn) {
defer dst.Close()
defer src.Close()
buf := make([]byte, 4096)
for {
n, err := src.Read(buf)
if err != nil {
// log.Println(`Read err:`, err)
return
}
// log.Println(src.RemoteAddr().String(), `=>`, dst.RemoteAddr().String(), `:`, len(buf[:n]))
_, err = dst.Write(buf[:n])
if err != nil {
// log.Println(`Write errL`, err)
return
}
}
}

func handleConn(lconn net.Conn) {
defer lconn.Close()
rconn, err := dialFunc(`tcp`, *proxyAddr)
if err != nil {
lconn.Close()
log.Println(err)
return
}
log.Println(`Connected to`, *proxyAddr)
defer rconn.Close()
go copy2(lconn, rconn)
copy2(rconn, lconn)
defer func () {
time.Sleep(time.Second)
rconn.Close()
lconn.Close()
}()
go io.Copy(lconn, rconn)
io.Copy(rconn, lconn)
log.Println(`Closed:`, lconn.RemoteAddr().String())
}

Expand Down

0 comments on commit a2a1569

Please sign in to comment.