I'm developing a simple network monitoring application that will adjust IPv4 settings on the machine based on what SSID you are connected to, everything I want to achieve is done and ready however my current method of detecting a change in SSID errors out if it cycles whilst I am switching Access Point. The detection itself is very rudimentary and rather primitive, though I lack enough experience in VB.Net to set up a proper event handler myself.
I tried waiting for
Wlan.WlanInterfaceState.NotReady
However this proved unsuccessful. I did go through the motions of googling my issue and looking to see if anyone else encountered a similar issue and the solutions they found also proved entirely unsuccessful in my case.
My main looping function is:
Public Sub WiFiScan()
If Wlan.WlanInterfaceState.NotReady Then
WhatAPResult = "WiFi is Off"
MsgBox("")
Else
WhatAP()
End If
MainForm.NetLabelAP.Text = ("Current AP: " + WhatAPResult)
End Sub
The WhatAP() function referenced here is:
Public Function WhatAP()
If wifiON() = True Then
Dim wlanx = New WlanClient()
If Wlan.WlanInterfaceState.NotReady Then
Else
Dim connectedSsids As Collection(Of [String]) = New Collection(Of String)()
For Each wlanInterface As WlanClient.WlanInterface In wlanx.Interfaces
Dim ssid As Wlan.Dot11Ssid = wlanInterface.CurrentConnection.wlanAssociationAttributes.dot11Ssid
connectedSsids.Add(New [String](Encoding.ASCII.GetChars(ssid.SSID, 0, CInt(ssid.SSIDLength))))
For Each item As String In connectedSsids
WhatAPResult = item
Return True 'CHANGE THE LABEL TO A TEXTBOX OR WHERE EVER YOU WANT TO DISPLAY YOUR CONNECTED WIFI'S NAME.
Next
Next
''CONTINUE ON FROM HERE.
End If
Else
Return False
End If
End Function
And WifiON() is a basic function in of itself:
Public Function wifiON()
Dim nics() As System.Net.NetworkInformation.NetworkInterface =
System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
For Each nic In nics
If nic.Name = "WiFi" And nic.OperationalStatus = OperationalStatus.Up Then
Return True
Exit Function
End If
Next
Return False
End Function
The error I get is:
System.ArgumentException: 'Type 'NativeWifi.Wlan+WlanReasonCode' cannot be marshaled as an unmanaged structure;
All I want is for the program to accurately detect a change in connected SSID so that I can react accordingly, however this issue is proving to best me well and truly.
Any insight or help would be greatly appreciated.