mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* 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
66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
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)}
|
||
}
|