mirror of
https://github.com/henrygd/beszel.git
synced 2026-10-01 05:47:48 +02:00
refactor(agent): label windows wifi interfaces by adapter name instead of GUID
This commit is contained in:
@@ -7,5 +7,6 @@ interval only; real-time requests reuse the last snapshot.
|
|||||||
|
|
||||||
- Linux: nl80211 via `github.com/mdlayher/wifi`. Docker needs `network_mode: host`.
|
- Linux: nl80211 via `github.com/mdlayher/wifi`. Docker needs `network_mode: host`.
|
||||||
- macOS: CoreWLAN via `osascript` (JXA). SSID may be redacted by privacy settings.
|
- macOS: CoreWLAN via `osascript` (JXA). SSID may be redacted by privacy settings.
|
||||||
- Windows: native WLAN API, keyed by interface GUID.
|
- Windows: native WLAN API, keyed by adapter alias (e.g. `Wi-Fi`), falling back
|
||||||
|
to interface GUID.
|
||||||
- Other platforms: unsupported.
|
- Other platforms: unsupported.
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ var wlanEnum = wlan.NewProc("WlanEnumInterfaces")
|
|||||||
var wlanQuery = wlan.NewProc("WlanQueryInterface")
|
var wlanQuery = wlan.NewProc("WlanQueryInterface")
|
||||||
var wlanFree = wlan.NewProc("WlanFreeMemory")
|
var wlanFree = wlan.NewProc("WlanFreeMemory")
|
||||||
|
|
||||||
|
var iphlpapi = windows.NewLazySystemDLL("iphlpapi.dll")
|
||||||
|
var guidToLuid = iphlpapi.NewProc("ConvertInterfaceGuidToLuid")
|
||||||
|
var luidToAlias = iphlpapi.NewProc("ConvertInterfaceLuidToAlias")
|
||||||
|
|
||||||
type wlanInterface struct {
|
type wlanInterface struct {
|
||||||
GUID windows.GUID
|
GUID windows.GUID
|
||||||
Description [256]uint16
|
Description [256]uint16
|
||||||
@@ -84,7 +88,7 @@ func collect(ctx context.Context) map[string]system.WiFi {
|
|||||||
}
|
}
|
||||||
wlanFree.Call(uintptr(data))
|
wlanFree.Call(uintptr(data))
|
||||||
}
|
}
|
||||||
result[iface.GUID.String()] = reading
|
result[interfaceName(&iface.GUID)] = reading
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -97,3 +101,20 @@ func queryWLAN(handle windows.Handle, guid *windows.GUID, opcode uintptr) (unsaf
|
|||||||
}
|
}
|
||||||
return data, size
|
return data, size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// interfaceName returns the adapter alias ("Wi-Fi"), matching the names used by
|
||||||
|
// network interface stats. Falls back to the GUID if the alias is unavailable.
|
||||||
|
func interfaceName(guid *windows.GUID) string {
|
||||||
|
if guidToLuid.Find() == nil && luidToAlias.Find() == nil {
|
||||||
|
var luid uint64
|
||||||
|
if rc, _, _ := guidToLuid.Call(uintptr(unsafe.Pointer(guid)), uintptr(unsafe.Pointer(&luid))); rc == 0 {
|
||||||
|
var alias [windows.IF_MAX_STRING_SIZE + 1]uint16
|
||||||
|
if rc, _, _ := luidToAlias.Call(uintptr(unsafe.Pointer(&luid)), uintptr(unsafe.Pointer(&alias[0])), uintptr(len(alias))); rc == 0 {
|
||||||
|
if name := windows.UTF16ToString(alias[:]); name != "" {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return guid.String()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user