41 lines
952 B
Go
41 lines
952 B
Go
//go:build windows
|
|
|
|
package winapi
|
|
|
|
import (
|
|
"bytes"
|
|
"os/exec"
|
|
"strings"
|
|
"syscall"
|
|
)
|
|
|
|
// GetWifiConnection đọc SSID và BSSID từ netsh (Windows)
|
|
func GetWifiConnection() WifiConnection {
|
|
cmd := exec.Command("netsh", "wlan", "show", "interfaces")
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
|
|
|
var out bytes.Buffer
|
|
cmd.Stdout = &out
|
|
if err := cmd.Run(); err != nil {
|
|
return WifiConnection{}
|
|
}
|
|
|
|
var conn WifiConnection
|
|
for _, line := range strings.Split(out.String(), "\n") {
|
|
trimmed := strings.TrimSpace(line)
|
|
lower := strings.ToLower(trimmed)
|
|
if strings.HasPrefix(lower, "ssid") && !strings.Contains(lower, "bssid") {
|
|
if v := valueAfterColon(trimmed); v != "" {
|
|
conn.SSID = v
|
|
}
|
|
}
|
|
// Windows: "AP BSSID" (EN) hoặc dòng có chứa "bssid" (locale khác)
|
|
if strings.Contains(lower, "bssid") {
|
|
if v := valueAfterColon(trimmed); v != "" {
|
|
conn.BSSID = normalizeMAC(v)
|
|
}
|
|
}
|
|
}
|
|
return conn
|
|
}
|