mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
48 lines
879 B
Go
48 lines
879 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 "darwin":
|
|
return dnsMacOS()
|
|
default:
|
|
return []string{runtime.GOOS}
|
|
}
|
|
}
|