-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
150 lines (129 loc) · 3.21 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
"os"
"log"
"net"
"github.com/gookit/color"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Commands: []*cli.Command {
{
Name: "nameserver",
Aliases: []string{"ns"},
Usage: "Check nameserver of any host",
Action: func(c *cli.Context) error {
if c.Args().Len() >= 2 {
color.Red.Println("Can only lookup one domain at a time")
return nil
}
// get host
host := c.Args().First()
// lookup host
ns, err := net.LookupNS(host)
if err != nil {
color.Red.Println(err.Error())
return nil
}
color.Style{color.FgCyan, color.OpBold}.Println("Nameservers for", host, ":")
for i := 0; i < len(ns); i++ {
color.Green.Println(ns[i].Host)
}
return nil
},
},
{
Name: "mailserver",
Aliases: []string{"mx"},
Usage: "Get mail servers for a domain",
Action: func(c *cli.Context) error {
if c.Args().Len() >= 2 {
color.Red.Println("Can only lookup one domain mx at a time")
return nil
}
// host
host := c.Args().First()
// lookup mail server
mx, err := net.LookupMX(host)
if err != nil {
color.Red.Println(err.Error())
return nil
}
color.Style{color.FgCyan, color.OpBold}.Println("Mailservers for", host, ":")
for i := 0; i < len(mx); i++ {
color.Green.Println("Mail Server Host:", mx[i].Host)
}
return nil
},
},
{
Name: "ip",
Usage: "Lookup IP address of a host",
Action: func(c *cli.Context) error {
if c.Args().Len() >= 2 {
color.Red.Println("Can only lookup one domain ip at a time")
return nil
}
// get host
host := c.Args().First()
ip, err := net.LookupIP(host)
if err != nil {
color.Red.Println(err.Error())
return nil
}
color.Style{color.FgCyan, color.OpBold}.Println("IP Addresses for", host, ":")
for i := 0; i < len(ip); i++ {
color.Green.Println("IP Address for:", ip[i].To16())
}
return nil
},
},
{
Name: "cname",
Usage: "Lookup cname of a host",
Action: func(c *cli.Context) error {
if c.Args().Len() >= 2 {
color.Red.Println("Can only lookup one domain ip at a time")
return nil
}
// get host
host := c.Args().First()
cname, err := net.LookupCNAME(host)
if err != nil {
color.Red.Println(err.Error())
return nil
}
color.Style{color.FgCyan, color.OpBold}.Println("CNAME Record for", host, ":")
color.Green.Println("CNAME Record for:", cname)
return nil
},
},
{
Name: "txt",
Usage: "Lookup txt of a host",
Action: func(c *cli.Context) error {
if c.Args().Len() >= 2 {
color.Red.Println("Can only lookup one domain ip at a time")
return nil
}
// get host
host := c.Args().First()
txt, err := net.LookupTXT(host)
if err != nil {
color.Red.Println(err.Error())
return nil
}
color.Style{color.FgCyan, color.OpBold}.Println("TXT Record for", host, ":")
for i := 0; i < len(txt); i++ {
color.Green.Println(txt[i])
}
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}