...
1
16
17 package dns
18
19 import (
20 "fmt"
21 "os"
22 "strings"
23
24 "github.com/spf13/cobra"
25 )
26
27
28 var CmdDNSSuffix = &cobra.Command{
29 Use: "dns-suffix",
30 Short: "Prints the host's DNS suffix list",
31 Long: `Prints the DNS suffixes of this host.`,
32 Args: cobra.MaximumNArgs(0),
33 Run: printDNSSuffixList,
34 }
35
36
37 var CmdDNSServerList = &cobra.Command{
38 Use: "dns-server-list",
39 Short: "Prints the host's DNS Server list",
40 Long: `Prints the DNS Server list of this host.`,
41 Args: cobra.MaximumNArgs(0),
42 Run: printDNSServerList,
43 }
44
45
46 var CmdEtcHosts = &cobra.Command{
47 Use: "etc-hosts",
48 Short: "Prints the host's /etc/hosts file",
49 Long: `Prints the "hosts" file of this host."`,
50 Args: cobra.MaximumNArgs(0),
51 Run: printHostsFile,
52 }
53
54 func printDNSSuffixList(cmd *cobra.Command, args []string) {
55 dnsSuffixList := GetDNSSuffixList()
56 fmt.Println(strings.Join(dnsSuffixList, ","))
57 }
58
59 func printDNSServerList(cmd *cobra.Command, args []string) {
60 dnsServerList := getDNSServerList()
61 fmt.Println(strings.Join(dnsServerList, ","))
62 }
63
64 func printHostsFile(cmd *cobra.Command, args []string) {
65 fmt.Println(readFile(etcHostsFile))
66 }
67
68 func readFile(fileName string) string {
69 fileData, err := os.ReadFile(fileName)
70 if err != nil {
71 panic(err)
72 }
73
74 return string(fileData)
75 }
76
View as plain text