SSID name
Posted: Fri Mar 17, 2023 8:11 pm
Is any way how to get active connected WiFi SSID name (or IP)?
THX
THX
Code: Select all
EnableExplicit
Define SSID.S
Procedure.S GetSSID()
Protected SSID.S
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_MacOS
Define WiFiInterface.I
Define WiFi.I
WiFi = CocoaMessage(0, 0, "CWWiFiClient sharedWiFiClient")
WiFiInterface = CocoaMessage(0, WiFi, "interface")
SSID = PeekS(CocoaMessage(0, CocoaMessage(0, WiFiInterface, "ssid"),
"UTF8String"), -1, #PB_UTF8)
CompilerCase #PB_OS_Linux
Define ConsoleCommand.I
Define Result.S
ConsoleCommand = RunProgram("iwgetid", "-r", "",
#PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
CompilerCase #PB_OS_Windows
Define ConsoleCommand.I
Define Result.S
ConsoleCommand = RunProgram("NetSh", "WLAN show profiles", "",
#PB_Program_Open | #PB_Program_Read)
CompilerEndSelect
CompilerIf #PB_Compiler_OS <> #PB_OS_MacOS
If ConsoleCommand = 0
MessageRequester("Error",
"Sorry, getting SSID failed!",
#PB_MessageRequester_Error)
ProcedureReturn ""
Else
While ProgramRunning(ConsoleCommand)
If AvailableProgramOutput(ConsoleCommand)
Result + ReadProgramString(ConsoleCommand)
EndIf
Wend
CloseProgram(ConsoleCommand)
EndIf
CompilerEndIf
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
SSID = Result
CompilerCase #PB_OS_Windows
SSID = Trim(StringField(Result, 3, ":"))
CompilerEndSelect
ProcedureReturn SSID
EndProcedure
SSID = GetSSID()
If SSID <> ""
MessageRequester("Info", "SSID: " + SSID, #PB_MessageRequester_Info)
EndIf