-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathshow-ip-dns-fqdns.go
89 lines (73 loc) · 1.67 KB
/
show-ip-dns-fqdns.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
package commands
import (
"fmt"
"os"
"github.com/activecm/rita-legacy/pkg/hostname"
"github.com/activecm/rita-legacy/resources"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli"
)
func init() {
command := cli.Command{
Name: "show-ip-dns-fqdns",
Usage: "Print FQDNs associated with IP Address via DNS",
ArgsUsage: "<database> <ip address>",
Flags: []cli.Flag{
ConfigFlag,
humanFlag,
delimFlag,
},
Action: showIPFqdns,
}
bootstrapCommands(command)
}
func showIPFqdns(c *cli.Context) error {
db, ip := c.Args().Get(0), c.Args().Get(1)
if db == "" || ip == "" {
return cli.NewExitError("Specify a database and IP address", -1)
}
res := resources.InitResources(getConfigFilePath(c))
res.DB.SelectDB(db)
fqdnResults, err := hostname.FQDNResults(res, ip)
if err != nil {
res.Log.Error(err)
return cli.NewExitError(err, -1)
}
if !(len(fqdnResults) > 0) {
return cli.NewExitError("No results were found for "+db, -1)
}
if c.Bool("human-readable") {
err := showIPFqdnsHuman(fqdnResults)
if err != nil {
return cli.NewExitError(err.Error(), -1)
}
return nil
}
err = showIPFqdnsRaw(fqdnResults)
if err != nil {
return cli.NewExitError(err.Error(), -1)
}
return nil
}
func showIPFqdnsHuman(data []*hostname.FQDNResult) error {
table := tablewriter.NewWriter(os.Stdout)
headerFields := []string{
"Queried FQDN",
}
table.SetHeader(headerFields)
for _, d := range data {
row := []string{
d.Hostname,
}
table.Append(row)
}
table.Render()
return nil
}
func showIPFqdnsRaw(data []*hostname.FQDNResult) error {
fmt.Println("Queried FQDN")
for _, d := range data {
fmt.Println(d.Hostname)
}
return nil
}