pingtunnel/cmd/main.go

61 lines
1.1 KiB
Go
Raw Normal View History

2018-12-16 08:56:40 +03:00
package main
import (
"flag"
"fmt"
"pingtunnel"
)
var usage = `
Usage:
2018-12-18 06:39:16 +03:00
pingtunnel -type server
2018-12-16 08:56:40 +03:00
2018-12-18 06:39:16 +03:00
pingtunnel -type client -l LOCAL_IP:4455 -s SERVER_IP -t 4455
2018-12-16 08:56:40 +03:00
`
func main() {
fmt.Println("start...")
t := flag.String("type", "client", "client or server")
listen := flag.String("l", ":4455", "listen addr")
2018-12-18 06:39:16 +03:00
target := flag.Int("t", 4455, "target port")
server := flag.String("s", "127.0.0.1", "server addr")
2018-12-16 08:56:40 +03:00
flag.Usage = func() {
fmt.Printf(usage)
}
flag.Parse()
if flag.NArg() != 0 {
flag.Usage()
return
}
fmt.Printf("type %s\n", *t)
fmt.Printf("listen %s\n", *listen)
2018-12-18 06:39:16 +03:00
fmt.Printf("server %s\n", *server)
fmt.Printf("target port %d\n", *target)
2018-12-16 08:56:40 +03:00
if *t == "server" {
2018-12-18 06:39:16 +03:00
s, err := pingtunnel.NewServer()
2018-12-16 08:56:40 +03:00
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
return
}
2018-12-18 06:39:16 +03:00
fmt.Printf("Server start\n")
2018-12-16 08:56:40 +03:00
s.Run()
}
if *t == "client" {
2018-12-18 06:39:16 +03:00
c, err := pingtunnel.NewClient(*listen, *server, *target)
2018-12-16 08:56:40 +03:00
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
return
}
2018-12-18 06:39:16 +03:00
fmt.Printf("Client Listen %s (%s) Server %s (%s) TargetPort %d:\n", c.Addr(), c.IPAddr(),
c.ServerAddr(), c.ServerIPAddr(), c.TargetPort())
2018-12-17 10:21:15 +03:00
c.Run()
2018-12-16 08:56:40 +03:00
}
}