silence more output, fix minor output bugs

This commit is contained in:
AJ ONeal 2021-06-21 23:22:34 -06:00
parent 66f2d41c6b
commit 8ba42a09a4
2 changed files with 13 additions and 9 deletions

View File

@ -24,13 +24,15 @@ func ver() string {
} }
func usage() { func usage() {
fmt.Fprintf(os.Stderr, "\nsclient %s\n"+ fmt.Fprintf(os.Stderr, "\n%s\n"+
"\nusage: sclient <remote> <local>\n"+ "\nusage: sclient <remote> <local>\n"+
"\n"+ "\n"+
" ex: sclient example.com 3000\n"+ " ex: sclient example.com 3000\n"+
" (sclient example.com:443 localhost:3000)\n"+ " (sclient example.com:443 localhost:3000)\n"+
"\n"+ "\n"+
" ex: sclient example.com:8443 0.0.0.0:4080\n"+ " ex: sclient example.com:8443 0.0.0.0:4080\n"+
"\n"+
" ex: sclient example.com:443 -\n"+
"\n", ver()) "\n", ver())
flag.PrintDefaults() flag.PrintDefaults()
fmt.Println() fmt.Println()
@ -46,7 +48,7 @@ func main() {
} }
flag.Usage = usage flag.Usage = usage
insecure := flag.Bool("k", false, "ignore bad TLS/SSL/HTTPS certificates") insecure := flag.Bool("k", false, "alias for --insecure")
silent := flag.Bool("s", false, "alias of --silent") silent := flag.Bool("s", false, "alias of --silent")
servername := flag.String("servername", "", "specify a servername different from <remote> (to disable SNI use an IP as <remote> and do use this option)") servername := flag.String("servername", "", "specify a servername different from <remote> (to disable SNI use an IP as <remote> and do use this option)")
flag.BoolVar(insecure, "insecure", false, "ignore bad TLS/SSL/HTTPS certificates") flag.BoolVar(insecure, "insecure", false, "ignore bad TLS/SSL/HTTPS certificates")

View File

@ -58,8 +58,10 @@ func (t *Tunnel) DialAndListen() error {
return err return err
} }
if !t.Silent {
fmt.Fprintf(os.Stdout, "[listening] %s:%d <= %s:%d\n", fmt.Fprintf(os.Stdout, "[listening] %s:%d <= %s:%d\n",
t.RemoteAddress, t.RemotePort, t.LocalAddress, t.LocalPort) t.RemoteAddress, t.RemotePort, t.LocalAddress, t.LocalPort)
}
for { for {
conn, err := ln.Accept() conn, err := ln.Accept()
@ -150,15 +152,15 @@ func (t *Tunnel) handleConnection(remote string, conn netReadWriteCloser) {
return return
} }
if "stdio" == conn.RemoteAddr().Network() {
if !t.Silent { if !t.Silent {
if "stdio" == conn.RemoteAddr().Network() {
fmt.Fprintf(os.Stdout, "(connected to %s:%d and reading from %s)\n", fmt.Fprintf(os.Stdout, "(connected to %s:%d and reading from %s)\n",
t.RemoteAddress, t.RemotePort, conn.RemoteAddr().String()) t.RemoteAddress, t.RemotePort, conn.RemoteAddr().String())
}
} else { } else {
fmt.Fprintf(os.Stdout, "[connect] %s => %s:%d\n", fmt.Fprintf(os.Stdout, "[connect] %s => %s:%d\n",
strings.Replace(conn.RemoteAddr().String(), "[::1]:", "localhost:", 1), t.RemoteAddress, t.RemotePort) strings.Replace(conn.RemoteAddr().String(), "[::1]:", "localhost:", 1), t.RemoteAddress, t.RemotePort)
} }
}
go pipe(conn, sclient, "local") go pipe(conn, sclient, "local")
pipe(sclient, conn, "remote") pipe(sclient, conn, "remote")