-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (77 loc) · 1.65 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
"log"
"net"
"os"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "Website Lookup CLI"
app.Usage = "Let's you query IPs, CNAMEs, MX records and Name Servers!"
// We'll be using the same flag for all our commands
// so we'll define it up here
myFlags := []cli.Flag{
cli.StringFlag{
Name: "host",
Value: "tutorialedge.net",
},
}
// we create our commands
app.Commands = []cli.Command{
{
Name: "ns",
Usage: "Looks Up the NameServers for a Particular Host",
Flags: myFlags,
// the action, or code that will be executed when
// we execute our `ns` command
Action: func(c *cli.Context) error {
// a simple lookup function
ns, err := net.LookupNS(c.String("host"))
if err != nil {
return err
}
// we log the results to our console
// using a trusty fmt.Println statement
for i := 0; i < len(ns); i++ {
fmt.Println(ns[i].Host)
}
return nil
},
},
{
Name: "ip",
Usage: "Looks up the IP addresses for a particular host",
Flags: myFlags,
Action: func(c *cli.Context) error {
ip, err := net.LookupIP(c.String("host"))
if err != nil {
fmt.Println(err)
}
for i := 0; i < len(ip); i++ {
fmt.Println(ip[i])
}
return nil
},
},
{
Name: "cname",
Usage: "Looks up the CNAME for a particular host",
Flags: myFlags,
Action: func(c *cli.Context) error {
cname, err := net.LookupCNAME(c.String("host"))
if err != nil {
fmt.Println(err)
}
fmt.Println(cname)
return nil
},
},
}
// start our application
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}