i've created the following code based on the classes i've found in the wmi
test console. it works however, both this code and in the wmi test console
it appears i'm getting two rssi signals from the same wifi nic...the first
has the "instancena me" of the nic driver...the second is just a "?"...each
have differing signal strengths. can someone explain? also, will there
definitely always only be one "active" wifi nic at any given time? i don't
want to display information for one nic whilst another (wifi or not) is
really the one with the active network connection.
tia...here's the code (sorry for the text wrapping):
' ===============
Imports System.Manageme nt
Public Class Network
#Region " structures "
Public Structure WirelessAccessP oint
Dim NetworkCard As String
Dim SignalStrength As Long
Dim SSID As String
End Structure
#End Region
#Region " properties "
Public Shared ReadOnly Property Connected() As Boolean
Get
Try
Dim assignedIp As String =
GetHostByName(G etHostName()).A ddressList(0).T oString
Return Not assignedIp = Net.IPAddress.P arse("127.0.0.1 ").ToString
Catch ex As Exception
Return False
End Try
End Get
End Property
#End Region
#Region " methods "
Public Shared Function WirelessAccessP oints() As WirelessAccessP oint()
Dim device As ManagementObjec t
Dim deviceName As String
Dim deviceOptions As New ObjectGetOption s
Dim devices() As String
Dim waps() As wirelessAccessP oint
Try
' get wap device names
Dim deviceClass As New ManagementClass ("root/WMI",
"MSNDis_80211_B SSIList", deviceOptions)
For Each device In deviceClass.Get Instances
deviceName = device.GetPrope rtyValue("Insta nceName").ToStr ing()
If Not deviceName.ToLo wer.EndsWith("m iniport") Then
Dim index As Integer = 0
If Not devices Is Nothing Then index = devices.Length
ReDim Preserve devices(index)
devices(index) = deviceName
End If
Next
If Not devices Is Nothing Then
' force a rescan of available waps
Dim scanClass As New ManagementClass ("root/WMI",
"MSNDis_80211_B ssIdListScan", deviceOptions)
Dim scanObject As ManagementObjec t = scanClass.Creat eInstance()
For Each deviceName In devices
scanObject("Act ive") = True
scanObject("Ins tanceName") = deviceName
scanObject("Unu sedParameter") = 1
scanObject.Put( )
'now, get signal strength
Dim sql As String = "SELECT * " &
vbCrLf & _
"FROM MSNDis_80211_BS SIList " &
vbCrLf & _
"WHERE Active = 'TRUE' " &
vbCrLf & _
"AND InstanceName = '" & deviceName
& "'"
Dim query As New ManagementObjec tSearcher("root/WMI", sql)
Dim wap As ManagementBaseO bject
Dim wapCollection As ManagementObjec tCollection = query.Get()
Dim wapEnumerator As
ManagementObjec tCollection.Man agementObjectEn umerator =
wapCollection.G etEnumerator
wapEnumerator.M oveNext()
For Each wap In
wapEnumerator.C urrent.Properti es("Ndis80211BS SIList").Value
Dim wirelessAccessP oint As New wirelessAccessP oint
With wirelessAccessP oint
.NetworkCard = deviceName
.SignalStrength =
CType(wap.GetPr opertyValue("Nd is80211Rssi").T oString, Long)
.SSID = New
String(Encoding .ASCII.GetChars (CType(wap.GetP ropertyValue("N dis80211Ssid"),
Byte()))).Trim
End With
Dim index As Integer = 0
If Not waps Is Nothing Then index = waps.Length
ReDim Preserve waps(index)
waps(index) = wirelessAccessP oint
Next
Next
End If
Return waps
Finally
End Try
Return Nothing
End Function
#End Region
End Class