diff options
| author | Jeff Carr <[email protected]> | 2025-03-09 09:41:53 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-03-09 09:41:53 -0500 |
| commit | 31c8c96c827c46e219e928e66d542e9c8f65bc6e (patch) | |
| tree | 3397eca3df5ed383e27ff6e4c445d84ba8f29456 /main.go | |
| parent | 2495995e6e50be78e8501eeeaf1a1b7cf067e6ae (diff) | |
try to listenv0.0.1
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 32 |
1 files changed, 21 insertions, 11 deletions
@@ -5,6 +5,7 @@ package main import ( "embed" + "fmt" "io" "net" "os" @@ -50,24 +51,32 @@ func main() { } // go NewWatchdog() - - go listen3000() - go startHTTP() + if gui.NoGui() { + all := me.portmaps.All() + for all.Scan() { + pm := all.Next() + if !pm.Enabled { + continue + } + log.Info("portmap enabled for port", pm.Listen, "to", pm.Connect) + gus3000(int(pm.Listen), pm.Connect) + } os.Exit(0) } doGui() } -func listen3000() { +func gus3000(port int, connect string) { // Listen on local port 3000 - listener, err := net.Listen("tcp", "0.0.0.0:3000") + s := fmt.Sprintf("0.0.0.0:%d", port) + listener, err := net.Listen("tcp", s) if err != nil { - log.Fatalf("Failed to listen on port 3000: %v", err) + log.Fatalf("Failed to listen on %s: %v", s, err) } defer listener.Close() - log.Println("Listening on port 3000...") + log.Info("Listening on ", s) for { // Accept incoming connection @@ -79,17 +88,18 @@ func listen3000() { log.Printf("Client connected: %s", clientConn.RemoteAddr()) // Handle the connection in a separate goroutine - go handleConnection(clientConn) + go handleConnection(clientConn, s) } } -func handleConnection(clientConn net.Conn) { +func handleConnection(clientConn net.Conn, where string) { defer clientConn.Close() // Connect to the target server - targetConn, err := net.Dial("tcp", "go.wit.com:44355") + // targetConn, err := net.Dial("tcp", "go.wit.com:80") + targetConn, err := net.Dial("tcp", where) if err != nil { - log.Printf("Failed to connect to go.wit.com %v", err) + log.Printf("Failed to connect to %s %v", where, err) return } defer targetConn.Close() |
