-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (85 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
84
85
86
87
88
89
90
91
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!"
app.UsageText = "cli [COMMAND] --host [HOSTNAME]"
app.Version = "0.1"
myFlags := []cli.Flag{
&cli.StringFlag{
Name: "host",
Value: "",
},
}
app.Commands = []cli.Command{
{
Name: "ns",
Usage: "Looks Up the NameServers for a Particular Host",
Flags: myFlags,
Action: func(c *cli.Context) error {
ns, err := net.LookupNS(c.String("host"))
if err != nil {
return err
}
for i := range ns {
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 {
return err
}
for i := range ip {
fmt.Println(ip[i])
}
return nil
},
},
{
Name: "cn",
Usage: "Looks Up the CNAME for a Particular Host",
Flags: myFlags,
Action: func(c *cli.Context) error {
cn, err := net.LookupCNAME(c.String("host"))
if err != nil {
return err
}
fmt.Println(cn)
return nil
},
},
{
Name: "mx",
Usage: "Looks Up the MX records for a Particular Host",
Flags: myFlags,
Action: func(c *cli.Context) error {
mx, err := net.LookupMX(c.String("host"))
if err != nil {
return err
}
for i := range mx {
fmt.Println(mx[i].Host, mx[i].Pref)
}
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}