-
Notifications
You must be signed in to change notification settings - Fork 50
/
main.go
55 lines (49 loc) · 1.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2014 RightScale, Inc. - see LICENSE
package main
import (
"fmt"
"net"
_ "net/http/pprof"
"os"
"strings"
"github.com/rightscale/wstunnel/tunnel"
"github.com/rightscale/wstunnel/whois"
"gopkg.in/inconshreveable/log15.v2"
)
func init() { tunnel.SetVV(VV) } // propagate version
func main() {
if len(os.Args) < 2 {
log15.Crit(fmt.Sprintf("Usage: %s [cli|srv|whois|version] [-options...]", os.Args[0]))
os.Exit(1)
}
switch os.Args[1] {
case "cli":
err := tunnel.NewWSTunnelClient(os.Args[2:]).Start()
if err != nil {
log15.Crit(err.Error())
os.Exit(1)
}
case "srv":
tunnel.NewWSTunnelServer(os.Args[2:]).Start(nil)
case "whois":
lookupWhois(os.Args[2:])
os.Exit(0)
case "version", "-version", "--version":
log15.Crit(VV)
os.Exit(1)
default:
log15.Crit(fmt.Sprintf("Usage: %s [cli|srv] [-options...]", os.Args[0]))
os.Exit(1)
}
<-make(chan struct{}, 0)
}
func lookupWhois(args []string) {
if len(args) != 2 {
log15.Crit("Usage: %s whois <whois-token> <ip-address>", os.Args[0])
os.Exit(1)
}
what := args[1]
names, _ := net.LookupAddr(what)
log15.Info("DNS ", "addr", what, "dns", strings.Join(names, ","))
log15.Info("WHOIS ", "addr", what, "dns", whois.Whois(what, args[0]))
}