1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/security/dns.go
E3V3A b67339662c Updated and improved the security widget
* Merged all windows kludges into unified files
* Removed window kludges
* Improved UI
* Fixed faulty Windows username detection
* Fixed dodgy Window firewall detection
* Fixed overlapping/overflowing DNS in UI
* Added fine-grained Windows firewall status
* Added correct and sanitized PowerShell Calls

Affcted Files:

	modified:   dns.go
	deleted:    dns_windows.go
	modified:   firewall.go
	modified:   users.go
	deleted:    users_windows.go
	renamed:    widget_windows.go -> widget.go
2019-02-05 10:52:13 +02:00

66 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package security
import (
"os/exec"
"runtime"
"strings"
"github.com/wtfutil/wtf/wtf"
)
/* -------------------- Exported Functions -------------------- */
func DnsServers() []string {
switch runtime.GOOS {
case "linux":
return dnsLinux()
case "darwin":
return dnsMacOS()
case "windows":
return dnsWindows()
default:
return []string{runtime.GOOS}
}
}
/* -------------------- Unexported Functions -------------------- */
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 {
cmdString := `scutil --dns | head -n 7 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'`
cmd := exec.Command("sh", "-c", cmdString)
out := wtf.ExecuteCommand(cmd)
lines := strings.Split(out, "\n")
if len(lines) > 0 {
return lines
}
return []string{}
}
func dnsWindows() []string {
cmd := exec.Command("powershell.exe", "-NoProfile", "Get-DnsClientServerAddress | Select-Object ExpandProperty ServerAddresses")
return []string{wtf.ExecuteCommand(cmd)}
}