mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
82 lines
1.6 KiB
Go
82 lines
1.6 KiB
Go
package security
|
|
|
|
import (
|
|
"os/exec"
|
|
"runtime"
|
|
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
)
|
|
|
|
// https://github.com/yelinaung/wifi-name/blob/master/wifi-name.go
|
|
const osxWifiCmd = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
|
|
const osxWifiArg = "-I"
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func wifiEncryptionLinux() string {
|
|
cmd := exec.Command("nmcli", "-t", "-f", "active,security", "dev", "wifi")
|
|
out := wtf.ExecuteCommand(cmd)
|
|
name := wtf.FindMatch(`yes:(.+)`, out)
|
|
if len(name) > 0 {
|
|
return name[0][1]
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func wifkEncryptionMacOS() string {
|
|
name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo())
|
|
return matchStr(name)
|
|
}
|
|
|
|
func WifiEncryption() string {
|
|
switch runtime.GOOS {
|
|
case "linux":
|
|
return wifiEncryptionLinux()
|
|
case "darwin":
|
|
return wifkEncryptionMacOS()
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
func wifiNameMacOS() string {
|
|
name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo())
|
|
return matchStr(name)
|
|
}
|
|
|
|
func wifiNameLinux() string {
|
|
cmd := exec.Command("nmcli", "-t", "-f", "active,ssid", "dev", "wifi")
|
|
out := wtf.ExecuteCommand(cmd)
|
|
name := wtf.FindMatch(`yes:(.+)`, out)
|
|
if len(name) > 0 {
|
|
return name[0][1]
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func WifiName() string {
|
|
switch runtime.GOOS {
|
|
case "linux":
|
|
return wifiNameLinux()
|
|
case "darwin":
|
|
return wifiNameMacOS()
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func wifiInfo() string {
|
|
cmd := exec.Command(osxWifiCmd, osxWifiArg)
|
|
return wtf.ExecuteCommand(cmd)
|
|
}
|
|
|
|
func matchStr(data [][]string) string {
|
|
if len(data) <= 1 {
|
|
return ""
|
|
} else {
|
|
return data[1][1]
|
|
}
|
|
}
|