1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/security/dns.go
2018-05-31 12:29:32 -07:00

48 lines
878 B
Go

package security
import (
"os/exec"
"runtime"
"strings"
"github.com/senorprogrammer/wtf/wtf"
)
func dnsLinux() []string {
// This may be very Ubuntu specific
cmd := exec.Command("nmcli", "device", "show")
out := wtf.ExecuteCommand(cmd)
lines := strings.Split(out, "\n")
dns := []string{}
for _, l := range lines {
if strings.HasPrefix(l, "IP4.DNS") {
parts := strings.Split(l, ":")
dns = append(dns, strings.TrimSpace(parts[1]))
}
}
return dns
}
func dnsMacOS() []string {
cmd := exec.Command("networksetup", "-getdnsservers", "Wi-Fi")
out := wtf.ExecuteCommand(cmd)
records := strings.Split(out, "\n")
if len(records) > 0 {
return records
} else {
return []string{}
}
}
func DnsServers() []string {
switch runtime.GOOS {
case "linux":
return dnsLinux()
case "macos":
return dnsMacOS()
default:
return []string{runtime.GOOS}
}
}