/
main.go
391 lines (318 loc) · 8.41 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
package main
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"strconv"
"strings"
"github.com/ammario/ipisp/v2"
"github.com/fatih/color"
"github.com/gocolly/colly"
"github.com/ipinfo/go/v2/ipinfo"
"github.com/olekukonko/tablewriter"
)
type Crtsr struct {
CommonName string `json:"common_name"`
NameValue string `json:"name_value"`
}
var banner = `
# ___ # ___ ___ # #
_/7 # <_*_> # <_*_> /\#/\ \-^-/ #=ooO=========Ooo=#
(o o) # (o o) # (o o) /(o o)\ (o o) # \\ (o o) // #
ooO--(_)--Ooo--8---(_)--Ooo--8---(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo---------(_)--------
`
//Find CNAME
func get_cname(name string) {
var domainName string
color.HiGreen("\n[✔] " + color.HiYellowString("CNAME"))
cname, _ := net.LookupCNAME(name)
domainName = get_domain(name)
data := [][]string{
{name, color.HiCyanString(domainName), color.HiCyanString(cname)},
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Domain or Subdomain", "Domain", "CNAME"})
table.SetRowLine(true)
for _, v := range data {
table.Append(v)
}
table.Render()
}
//Find txt records
func get_txt_record(name string) {
var domainName string
color.HiGreen("\n[✔] " + color.HiYellowString("TXT records"))
txtrecords, _ := net.LookupTXT(name)
domainName = get_domain(name)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Domain", "TXT Records"})
table.SetRowLine(true)
table.SetAutoMergeCells(true)
for _, txt := range txtrecords {
data := [][]string{
{domainName, color.HiMagentaString(txt)},
}
for _, v := range data {
table.Append(v)
}
}
table.Render()
}
//Find IP informations
func get_ip(name string) {
var domainName string
color.HiGreen("\n[✔] " + color.HiYellowString("IP Informations"))
iprecords, _ := net.LookupIP(name)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Domain", "IP", "City and Country", "Location", "Organization", "IPISP",
})
table.SetRowLine(true)
table.SetAutoMergeCells(true)
domainName = get_domain(name)
for _, ip := range iprecords {
// Get IPISP
resp, err := ipisp.LookupIP(context.Background(), net.ParseIP(ip.String()))
if err != nil {
panic(err)
}
resp, err = ipisp.LookupASN(context.Background(), ipisp.ASN(resp.ASN))
if err != nil {
panic(err)
}
city, err := ipinfo.GetIPCity(ip)
if err != nil {
log.Fatal(err)
}
country, err := ipinfo.GetIPCountry(ip)
if err != nil {
log.Fatal(err)
}
location, err := ipinfo.GetIPLocation(ip)
if err != nil {
log.Fatal(err)
}
organization, err := ipinfo.GetIPOrg(ip)
if err != nil {
log.Fatal(err)
}
data := [][]string{{
domainName,
ip.String(),
color.HiGreenString(city + ", " + country),
color.HiGreenString(location),
color.HiGreenString(organization),
color.HiCyanString(resp.ISPName),
}}
for _, v := range data {
table.Append(v)
}
}
table.Render()
}
//Find nameserver(s)
func get_ns(name string) {
var domainName string
color.HiGreen("\n[✔] " + color.HiYellowString("Name Servers"))
nss, _ := net.LookupNS(name)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Domain", "Name Servers"})
table.SetRowLine(true)
table.SetAutoMergeCells(true)
domainName = get_domain(name)
for _, ns := range nss {
data := [][]string{
{domainName, color.HiRedString(ns.Host)},
}
for _, v := range data {
table.Append(v)
}
}
table.Render()
}
//Find MX record
func get_mx_record(name string) {
var domainName string
color.HiGreen("\n[✔] " + color.HiYellowString("MX Records"))
mxrecords, _ := net.LookupMX(name)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Domain", "MX Records"})
table.SetRowLine(true)
table.SetAutoMergeCells(true)
domainName = get_domain(name)
for _, mx := range mxrecords {
s := mx.Pref
data := [][]string{{
domainName,
color.HiCyanString(mx.Host) + " " + color.HiGreenString(strconv.Itoa(int(s))),
}}
for _, v := range data {
table.Append(v)
}
}
table.Render()
}
// Function get domain
func get_domain(name string) string {
hostName := strings.TrimSpace(name)
hostParts := strings.Split(hostName, ".")
lengthOfHostParts := len(hostParts)
if lengthOfHostParts == 3 {
name = strings.Join([]string{hostParts[1], hostParts[2]}, ".")
} else if lengthOfHostParts == 4 {
name = strings.Join([]string{hostParts[2], hostParts[3]}, ".")
} else if lengthOfHostParts == 5 {
name = strings.Join([]string{hostParts[3], hostParts[4]}, ".")
}
return name
}
// Get Subdomain
func GetJsonFromCrt(domain string) ([]string, error) {
resp, err := http.Get(fmt.Sprintf("https://crt.sh/?q=%s&output=json", domain))
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
sb := []byte(body)
var subdomains []Crtsr
err = json.Unmarshal(sb, &subdomains)
if err != nil {
panic(err)
}
output := make([]string, 0)
for _, subdomains := range subdomains {
output = append(output, subdomains.CommonName)
output = append(output, subdomains.NameValue)
}
return output, nil
}
func removeDuplicateValues(strSlice []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range strSlice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
func get_subdomain(name string) {
var domainName string
color.HiGreen("\n[✔] " + color.HiYellowString("Subdomain"))
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Domain", "Subdomain"})
table.SetRowLine(true)
table.SetAutoMergeCells(true)
subdomain, err := GetJsonFromCrt(name)
if err != nil {
panic(err)
}
removeDuplicateValuesSlice := removeDuplicateValues(subdomain)
for _, uniquesubdomain := range removeDuplicateValuesSlice {
// fmt.Println(uniquesubdomain)
domainName = get_domain(name)
data := [][]string{
{color.HiCyanString(domainName), color.HiGreenString(uniquesubdomain)},
}
for _, v := range data {
table.Append(v)
}
}
table.Render()
}
// Extract Link: https://github.com/ductnn/cUrls
func get_links(name string) {
color.HiGreen("\n[✔] " + color.HiYellowString("Extract URL"))
name = "https://" + name
c := colly.NewCollector(
colly.AllowedDomains(),
)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Domain", "Link found"})
table.SetRowLine(true)
table.SetAutoMergeCells(true)
c.OnHTML("a[href]", func(e *colly.HTMLElement) {
link := e.Attr("href")
data := [][]string{
{color.HiCyanString(name), color.HiBlueString(link)},
}
for _, v := range data {
table.Append(v)
}
})
c.Visit(name)
table.Render()
}
// End
func end_program() {
var goodbye, githubURL, dockerURL string
goodbye = "Star the project on GitHub if you liked this tool"
githubURL = "https://github.com/ductnn/lookup"
dockerURL = "https://hub.docker.com/r/ductn4/loo"
color.HiWhite("\n🐳 You can pull docker image in: " + color.HiCyanString(dockerURL))
color.HiGreen("\n⭐️ " + goodbye)
color.HiYellow("\n👉 " + githubURL + " 👈")
color.HiWhite("\n🎉 Thank you so much 🎉")
fmt.Printf("\n")
}
func main() {
var name string
color.Green("%s", banner)
color.Blue("\nEnter subdomain or domain name:")
fmt.Scanf("%s", &name)
var choice int
color.Blue("\nEnter your choice:")
fmt.Printf("\n")
color.Green("[1] - CNAME lookup")
color.Green("[2] - Subdomain lookup")
color.Green("[3] - TXT Records lookup")
color.Green("[4] - IP information lookup")
color.Green("[5] - NameServers lookup")
color.Green("[6] - MX Records lookup")
color.Green("[7] - Extract URL")
color.Green("[8] - Lookup all without subdomains")
color.Green("[9] - ALL")
fmt.Printf("\n")
fmt.Scanf("%d", &choice)
if choice == 1 {
get_cname(name)
} else if choice == 2 {
get_subdomain(name)
} else if choice == 3 {
get_txt_record(name)
} else if choice == 4 {
get_ip(name)
} else if choice == 5 {
get_ns(name)
} else if choice == 6 {
get_mx_record(name)
} else if choice == 7 {
get_links(name)
} else if choice == 8 {
get_cname(name)
get_txt_record(name)
get_ip(name)
get_ns(name)
get_mx_record(name)
get_links(name)
} else if choice == 9 {
get_cname(name)
get_subdomain(name)
get_txt_record(name)
get_ip(name)
get_ns(name)
get_mx_record(name)
get_links(name)
}
end_program()
}