From 02d518db5c9569c44401433112baf1be57921dbb Mon Sep 17 00:00:00 2001 From: Woodward Date: Mon, 30 Jul 2018 16:27:40 -0500 Subject: [PATCH] Adding English Windows support to the wifi module. --- security/wifi.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/security/wifi.go b/security/wifi.go index 30b75767..d05718f9 100644 --- a/security/wifi.go +++ b/security/wifi.go @@ -3,6 +3,7 @@ package security import ( "os/exec" "runtime" + "strings" "github.com/senorprogrammer/wtf/wtf" ) @@ -19,6 +20,8 @@ func WifiEncryption() string { return wifiEncryptionLinux() case "darwin": return wifiEncryptionMacOS() + case "windows": + return wifiEncryptionWindows() default: return "" } @@ -30,6 +33,8 @@ func WifiName() string { return wifiNameLinux() case "darwin": return wifiNameMacOS() + case "windows": + return wifiNameWindows() default: return "" } @@ -82,3 +87,36 @@ func matchStr(data [][]string) string { return data[1][1] } } + +//Windows +func wifiEncryptionWindows() string { + return parseWlanNetsh("Authentication") +} + +func wifiNameWindows() string { + return parseWlanNetsh("SSID") +} + +func parseWlanNetsh(target string) string { + cmd := exec.Command("netsh.exe", "wlan", "show", "interfaces") + out, err := cmd.Output() + if err != nil { + return "" + } + splits := strings.Split(string(out), "\n") + var words []string + for _, line := range splits { + token := strings.Split(string(line), ":") + for _, word := range token { + words = append(words, strings.TrimSpace(word)) + } + } + for i, token := range words { + switch token { + case target: + return words[i+1] + i++ + } + } + return "N/A" +}