Torna al Thread

[CODE] Imports System.Runtime.InteropServices Public NotInheritable Class Wifi Private Sub New() End Sub Public Shared Function GetInfo() As List(Of WiFiInfo) Dim result As New List(Of WiFiInfo)() Dim handle As IntPtr = IntPtr.Zero Dim negotiatedVersion As UInteger Try If WlanOpenHandle(1, IntPtr.Zero, negotiatedVersion, handle) <> 0 Then Return result End If Dim ptr As New IntPtr() If WlanEnumInterfaces(handle, IntPtr.Zero, ptr) <> 0 Then Return result End If Dim infoList As New WLAN_INTERFACE_INFO_LIST(ptr) WlanFreeMemory(ptr) Dim guid As Guid Dim dataSize As UInteger For i As Integer = 0 To infoList.dwNumberofItems - 1 Dim item As New WiFiInfo() item.InterfaceName = infoList.InterfaceInfo(i).strInterfaceDescription item.WLANInterfaceState = infoList.InterfaceInfo(i).isState guid = infoList.InterfaceInfo(i).InterfaceGuid If WlanQueryInterface(handle, guid, WLAN_INTF_OPCODE.wlan_intf_opcode_current_connection, IntPtr.Zero, dataSize, ptr, _ IntPtr.Zero) <> 0 Then result.Add(item) Return result End If item.Connection = CType(Marshal.PtrToStructure(ptr, GetType(WLAN_CONNECTION_ATTRIBUTES)), WLAN_CONNECTION_ATTRIBUTES) result.Add(item) WlanFreeMemory(ptr) Next Finally If handle <> IntPtr.Zero Then WlanCloseHandle(handle, IntPtr.Zero) End If End Try Return result End Function <DllImport("Wlanapi", EntryPoint:="WlanQueryInterface")> _ Public Shared Function WlanQueryInterface(<[In]()> hClientHandle As IntPtr, <[In]()> ByRef pInterfaceGuid As Guid, OpCode As WLAN_INTF_OPCODE, pReserved As IntPtr, <Out()> ByRef pdwDataSize As UInteger, ByRef ppData As IntPtr, _ pWlanOpcodeValueType As IntPtr) As UInteger End Function <DllImport("Wlanapi", EntryPoint:="WlanOpenHandle")> _ Public Shared Function WlanOpenHandle(dwClientVersion As UInteger, pReserved As IntPtr, <Out()> ByRef pdwNegotiatedVersion As UInteger, ByRef ClientHandle As IntPtr) As UInteger End Function <DllImport("Wlanapi", EntryPoint:="WlanEnumInterfaces")> _ Public Shared Function WlanEnumInterfaces(<[In]()> hClientHandle As IntPtr, pReserved As IntPtr, ByRef ppInterfaceList As IntPtr) As UInteger End Function <DllImport("Wlanapi", EntryPoint:="WlanFreeMemory")> _ Public Shared Sub WlanFreeMemory(<[In]()> pMemory As IntPtr) End Sub <DllImport("Wlanapi", EntryPoint:="WlanCloseHandle")> _ Public Shared Function WlanCloseHandle(<[In]()> hClientHandle As IntPtr, pReserved As IntPtr) As UInteger End Function End Class Public Structure WiFiInfo Public InterfaceName As String Public WLANInterfaceState As WLAN_INTERFACE_STATE Public Connection As WLAN_CONNECTION_ATTRIBUTES End Structure Public Enum WLAN_INTERFACE_STATE wlan_interface_state_not_ready = 0 wlan_interface_state_connected = 1 wlan_interface_state_ad_hoc_network_formed = 2 wlan_interface_state_disconnecting = 3 wlan_interface_state_disconnected = 4 wlan_interface_state_associating = 5 wlan_interface_state_discovering = 6 wlan_interface_state_authenticating = 7 End Enum <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _ Public Structure WLAN_CONNECTION_ATTRIBUTES Public isState As WLAN_INTERFACE_STATE Public wlanConnectionMode As WLAN_CONNECTION_MODE <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _ Public strProfileName As String Public wlanAssociationAttributes As WLAN_ASSOCIATION_ATTRIBUTES Public wlanSecurityAttributes As WLAN_SECURITY_ATTRIBUTES End Structure <StructLayout(LayoutKind.Sequential)> _ Public Structure WLAN_SECURITY_ATTRIBUTES <MarshalAs(UnmanagedType.Bool)> _ Public bSecurityEnabled As Boolean <MarshalAs(UnmanagedType.Bool)> _ Public bOneXEnabled As Boolean Public dot11AuthAlgorithm As DOT11_AUTH_ALGORITHM Public dot11CipherAlgorithm As DOT11_CIPHER_ALGORITHM End Structure Public Enum DOT11_CIPHER_ALGORITHM DOT11_CIPHER_ALGO_NONE = 0 DOT11_CIPHER_ALGO_WEP40 = 1 DOT11_CIPHER_ALGO_TKIP = 2 DOT11_CIPHER_ALGO_CCMP = 4 DOT11_CIPHER_ALGO_WEP104 = 5 DOT11_CIPHER_ALGO_WPA_USE_GROUP = 256 DOT11_CIPHER_ALGO_RSN_USE_GROUP = 256 DOT11_CIPHER_ALGO_WEP = 257 DOT11_CIPHER_ALGO_IHV_START = -2147483648 DOT11_CIPHER_ALGO_IHV_END = -1 End Enum Public Enum DOT11_AUTH_ALGORITHM DOT11_AUTH_ALGO_80211_OPEN = 1 DOT11_AUTH_ALGO_80211_SHARED_KEY = 2 DOT11_AUTH_ALGO_WPA = 3 DOT11_AUTH_ALGO_WPA_PSK = 4 DOT11_AUTH_ALGO_WPA_NONE = 5 DOT11_AUTH_ALGO_RSNA = 6 DOT11_AUTH_ALGO_RSNA_PSK = 7 DOT11_AUTH_ALGO_IHV_START = -2147483648 DOT11_AUTH_ALGO_IHV_END = -1 End Enum <StructLayout(LayoutKind.Explicit, CharSet:=CharSet.Unicode)> _ Public Structure WLAN_ASSOCIATION_ATTRIBUTES <FieldOffset(0)> _ Public dot11Ssid As DOT11_SSID <FieldOffset(&H24)> _ Public dot11BssType As DOT11_BSS_TYPE <FieldOffset(40)> _ Public dot11Bssid As DOT11_MAC_ADDRESS <FieldOffset(&H30)> _ Public dot11PhyType As DOT11_PHY_TYPE <FieldOffset(&H34)> _ Public uDot11PhyIndex As ULong <FieldOffset(&H38)> _ Public wlanSignalQuality As Int32 <FieldOffset(60)> _ Public ulRxRate As ULong <FieldOffset(&H40)> _ Public ulTxRate As ULong End Structure <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Public Structure DOT11_MAC_ADDRESS Public one As Byte Public two As Byte Public three As Byte Public four As Byte Public five As Byte Public six As Byte End Structure Public Enum DOT11_BSS_TYPE dot11_BSS_type_infrastructure = 1 dot11_BSS_type_independent = 2 dot11_BSS_type_any = 3 End Enum Public Enum DOT11_PHY_TYPE dot11_phy_type_unknown dot11_phy_type_any dot11_phy_type_fhss dot11_phy_type_dsss dot11_phy_type_irbaseband dot11_phy_type_ofdm dot11_phy_type_hrdsss dot11_phy_type_erp dot11_phy_type_ht dot11_phy_type_IHV_start dot11_phy_type_IHV_end End Enum <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _ Public Structure DOT11_SSID Public uSSIDLength As UInteger <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _ Public ucSSID As String End Structure Public Enum WLAN_CONNECTION_MODE wlan_connection_mode_profile = 0 wlan_connection_mode_temporary_profile wlan_connection_mode_discovery_secure wlan_connection_mode_discovery_unsecure wlan_connection_mode_auto wlan_connection_mode_invalid End Enum Public Enum WLAN_INTF_OPCODE wlan_intf_opcode_autoconf_start = 0 wlan_intf_opcode_autoconf_enabled wlan_intf_opcode_background_scan_enabled wlan_intf_opcode_media_streaming_mode wlan_intf_opcode_radio_state wlan_intf_opcode_bss_type wlan_intf_opcode_interface_state wlan_intf_opcode_current_connection wlan_intf_opcode_channel_number wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs wlan_intf_opcode_supported_adhoc_auth_cipher_pairs wlan_intf_opcode_supported_country_or_region_string_list wlan_intf_opcode_current_operation_mode wlan_intf_opcode_supported_safe_mode wlan_intf_opcode_certified_safe_mode wlan_intf_opcode_autoconf_end = 268435455 wlan_intf_opcode_msm_start = 268435712 wlan_intf_opcode_statistics wlan_intf_opcode_rssi wlan_intf_opcode_msm_end = 536870911 wlan_intf_opcode_security_start = 536936448 wlan_intf_opcode_security_end = 805306367 wlan_intf_opcode_ihv_start = 805306368 wlan_intf_opcode_ihv_end = 1073741823 End Enum <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _ Public Structure WLAN_INTERFACE_INFO Public InterfaceGuid As Guid <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _ Public strInterfaceDescription As String Public isState As WLAN_INTERFACE_STATE End Structure <StructLayout(LayoutKind.Sequential)> _ Public Structure WLAN_INTERFACE_INFO_LIST Public dwNumberofItems As Int32 Public dwIndex As Int32 Public InterfaceInfo As WLAN_INTERFACE_INFO() Public Sub New(pList As IntPtr) dwNumberofItems = Marshal.ReadInt32(pList, 0) dwIndex = Marshal.ReadInt32(pList, 4) InterfaceInfo = New WLAN_INTERFACE_INFO(dwNumberofItems - 1) {} For i As Integer = 0 To dwNumberofItems - 1 Dim pItemList As New IntPtr(pList.ToInt32() + (i * 532) + 8) Dim wii As New WLAN_INTERFACE_INFO() wii = CType(Marshal.PtrToStructure(pItemList, GetType(WLAN_INTERFACE_INFO)), WLAN_INTERFACE_INFO) InterfaceInfo(i) = wii Next End Sub End Structure [/CODE]
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5