pingtunnel/cmd/main.go

58 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-17 10:21:15 +03:00
pingtunnel -type server -t TARGET_IP:4455
2018-12-16 08:56:40 +03:00
2018-12-17 10:21:15 +03:00
pingtunnel -type client -l LOCAL_IP:4455 -t SERVER_IP
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")
target := flag.String("t", ":443", "target addr")
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)
fmt.Printf("target %s\n", *target)
if *t == "server" {
2018-12-17 10:21:15 +03:00
s, err := pingtunnel.NewServer(*target)
2018-12-16 08:56:40 +03:00
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
return
}
2018-12-17 10:21:15 +03:00
fmt.Printf("Server Target %s (%s):\n", s.TargetAddr(), s.TargetIPAddr())
2018-12-16 08:56:40 +03:00
s.Run()
}
if *t == "client" {
2018-12-17 10:21:15 +03:00
c, err := pingtunnel.NewClient(*listen, *target)
2018-12-16 08:56:40 +03:00
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
return
}
2018-12-16 14:32:23 +03:00
fmt.Printf("Client Listen %s (%s) Target %s (%s):\n", c.Addr(), c.IPAddr(), c.TargetAddr(), c.TargetIPAddr())
2018-12-17 10:21:15 +03:00
c.Run()
2018-12-16 08:56:40 +03:00
}
}