internal InterfaceInfoEx(WLAN_INTERFACE_INFO info, WLAN_CONNECTION_ATTRIBUTES attributes) : base(info) { ConnectionMode = (ConnectionMode)attributes.wlanConnectionMode; ProfileName = attributes.strProfileName; AssociationAttributes = new AssociationAttributes(attributes.wlanAssociationAttributes); SecurityAttributes = new SecurityAttributes(attributes.wlanSecurityAttributes); }
public WLAN_INTERFACE_INFO_LIST(IntPtr pList) { NumberOfItems = Marshal.ReadInt32(pList, 0); Index = Marshal.ReadInt32(pList, 4); InterfaceInfo = new WLAN_INTERFACE_INFO[NumberOfItems]; for (int i = 0; i < NumberOfItems; i++) { IntPtr pItemList = new IntPtr(pList.ToInt32() + (i * 284)); WLAN_INTERFACE_INFO wii = new WLAN_INTERFACE_INFO(); byte[] intGuid = new byte[16]; for (int j = 0; j < 16; j++) { intGuid[j] = Marshal.ReadByte(pItemList, 8 + j); } wii.InterfaceGuid = new Guid(intGuid); //wii.InterfacePtr = new IntPtr(pItemList.ToInt32() + 8); wii.InterfaceDescription = Marshal.PtrToStringUni(new IntPtr(pItemList.ToInt32() + 24), 256).Replace("\0", ""); wii.State = (WLAN_INTERFACE_STATE)Marshal.ReadInt32(pItemList, 280); InterfaceInfo[i] = wii; } }
public static WlanBssEntry[] NetworkBssList(WLAN_INTERFACE_INFO wanInter) { IntPtr bssListPtr; WlanGetNetworkBssList(m_pClientHandle, wanInter.InterfaceGuid, IntPtr.Zero, DOT11_BSS_TYPE.dot11_BSS_type_any, false, IntPtr.Zero, out bssListPtr); return(ConvertBssListPtr(bssListPtr)); }
private static InterfaceInfo ConvertToInterfaceInfo(WLAN_INTERFACE_INFO info) { return(new InterfaceInfo( id: info.InterfaceGuid, description: info.strInterfaceDescription, state: (InterfaceState)info.isState)); // The values of two enumerations are identical. }
/// <summary> /// Constructor /// </summary> internal InterfaceConnectionInfo( WLAN_INTERFACE_INFO info, ConnectionMode connectionMode, bool isRadioOn, bool isConnected, string profileName) : base(info) { this.ConnectionMode = connectionMode; this.IsRadioOn = isRadioOn; this.IsConnected = isConnected; this.ProfileName = profileName; }
public WLAN_INTERFACE_INFO_LIST(IntPtr pList) { dwNumberOfItems = Marshal.ReadInt32(pList, 0); dwIndex = Marshal.ReadInt32(pList, 4); InterfaceInfo = new WLAN_INTERFACE_INFO[dwNumberOfItems]; for (int i = 0; i < dwNumberOfItems; i++) { IntPtr pItemList = new IntPtr(pList.ToInt32() + (i * 532) + 8); WLAN_INTERFACE_INFO wii = new WLAN_INTERFACE_INFO(); wii = (WLAN_INTERFACE_INFO)Marshal.PtrToStructure(pItemList, typeof(WLAN_INTERFACE_INFO)); InterfaceInfo[i] = wii; } }
public WLAN_INTERFACE_INFO_LIST(IntPtr pList) { // The first 4 bytes are the number of WLAN_INTERFACE_INFO structures. dwNumberofItems = (int)Marshal.ReadInt64(pList, 0); // The next 4 bytes are the index of the current item in the unmanaged API. dwIndex = (int)Marshal.ReadInt64(pList, 4); // Construct the array of WLAN_INTERFACE_INFO structures. InterfaceInfo = new WLAN_INTERFACE_INFO[dwNumberofItems]; for (int i = 0; i < dwNumberofItems; i++) { // The offset of the array of structures is 8 bytes past the beginning. Then, take the index and multiply it by the number of bytes in the structure. // the length of the WLAN_INTERFACE_INFO structure is 532 bytes - this was determined by doing a sizeof(WLAN_INTERFACE_INFO) in an unmanaged C++ app. IntPtr pItemList = new IntPtr(pList.ToInt64() + (i * 532) + 8); // Construct the WLAN_INTERFACE_INFO structure, marshal the unmanaged structure into it, then copy it to the array of structures. WLAN_INTERFACE_INFO wii = new WLAN_INTERFACE_INFO(); wii = (WLAN_INTERFACE_INFO)Marshal.PtrToStructure(pItemList, typeof(WLAN_INTERFACE_INFO)); InterfaceInfo[i] = wii; } }
public WLAN_INTERFACE_INFO_LIST(IntPtr pList) { int iByteCount = 0; dwNumberOfItems = Marshal.ReadInt32(pList, iByteCount); iByteCount += Marshal.SizeOf(dwNumberOfItems.GetType()); dwIndex = Marshal.ReadInt32(pList, iByteCount); iByteCount += Marshal.SizeOf(dwIndex.GetType()); int ifListStartOffset = iByteCount; int ifListItemSize = Marshal.SizeOf(typeof(Int32)) * 5 + 2 * 256; // Int32*4 + WCHAR[256] + Int32 InterfaceInfo = new WLAN_INTERFACE_INFO[dwNumberOfItems]; for (int i = 0; i < dwNumberOfItems; i++) { // The offset of the array of structures is 8 bytes past the beginning. Then, take the index and multiply it by the number of bytes in the structure. IntPtr pItemList = new IntPtr(pList.ToInt32() + (i * ifListItemSize) + iByteCount); WLAN_INTERFACE_INFO wii = new WLAN_INTERFACE_INFO(); wii = (WLAN_INTERFACE_INFO)Marshal.PtrToStructure(pItemList, typeof(WLAN_INTERFACE_INFO)); InterfaceInfo[i] = wii; } }
public override IEnumerable <CommandDTOBase?> Execute(string[] args) { int numberOfInterfaces = 0; int numberOfProfiles = 0; List <WifiProfileEntry> wifiProfileEntries = new List <WifiProfileEntry>(); string profile; string sSID; string authentication; string passPhrase; string wifiInterface; object state; var ClientHandle = IntPtr.Zero; uint NegotiatedVersion = 0; var ret = WlanOpenHandle(2, IntPtr.Zero, out NegotiatedVersion, out ClientHandle); if (ret == Interop.Win32Error.Success) { var InterfaceListPtr = IntPtr.Zero; var retWlanEnum = WlanEnumInterfaces(ClientHandle, IntPtr.Zero, ref InterfaceListPtr); if (retWlanEnum == Interop.Win32Error.Success) { numberOfInterfaces = Marshal.ReadInt32(InterfaceListPtr); var WlanInterfaceInfoPtr = (IntPtr)(InterfaceListPtr.ToInt64() + 8); for (int i = 0; i < numberOfInterfaces; i++) { WLAN_INTERFACE_INFO WlanInterfaceInfo = (WLAN_INTERFACE_INFO)Marshal.PtrToStructure(WlanInterfaceInfoPtr, typeof(WLAN_INTERFACE_INFO)); wifiInterface = WlanInterfaceInfo.strInterfaceDescription; state = (StateEnum)WlanInterfaceInfo.isState; IntPtr ProfileListPtr = IntPtr.Zero; var retGetProfileList = WlanGetProfileList(ClientHandle, WlanInterfaceInfo.InterfaceGuid, IntPtr.Zero, out ProfileListPtr); if (retGetProfileList == Interop.Win32Error.Success) { int currentNbrOfProfiles = Marshal.ReadInt32(ProfileListPtr); //Get total of profiles for all interfaces numberOfProfiles += currentNbrOfProfiles; // Calculate the pointer to the first WLAN_PROFILE_INFO structure var WlanProfileInfoPtr = (IntPtr)(ProfileListPtr.ToInt64() + 8); // dwNumberOfItems + dwIndex for (int j = 0; j < currentNbrOfProfiles; j++) { WLAN_PROFILE_INFO WlanProfileInfo = (WLAN_PROFILE_INFO)Marshal.PtrToStructure(WlanProfileInfoPtr, typeof(WLAN_PROFILE_INFO)); string ProfileXml = ""; UInt32 WlanProfileFlags = 4; // WLAN_PROFILE_GET_PLAINTEXT_KEY UInt32 WlanProfileAccessFlags = 0; var retGetProfile = WlanGetProfile(ClientHandle, WlanInterfaceInfo.InterfaceGuid, WlanProfileInfo.strProfileName, IntPtr.Zero, out ProfileXml, ref WlanProfileFlags, out WlanProfileAccessFlags); if (retGetProfile == Interop.Win32Error.Success) { var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(ProfileXml); XmlNamespaceManager mgr = new XmlNamespaceManager(xmlDoc.NameTable); mgr.AddNamespace("ns", "http://www.microsoft.com/networking/WLAN/profile/v1"); profile = ""; sSID = ""; authentication = ""; passPhrase = ""; //Catch if keyMaterial is empty try { profile = xmlDoc.SelectSingleNode("//ns:WLANProfile/ns:name", mgr).InnerText; sSID = xmlDoc.SelectSingleNode("//ns:WLANProfile/ns:SSIDConfig/ns:SSID/ns:name", mgr).InnerText; passPhrase = xmlDoc.SelectSingleNode("//ns:WLANProfile/ns:MSM/ns:security/ns:sharedKey/ns:keyMaterial", mgr).InnerText; authentication = xmlDoc.SelectSingleNode("//ns:WLANProfile/ns:MSM/ns:security/ns:authEncryption/ns:authentication", mgr).InnerText; } catch { } WifiProfileEntry CurrentWifiProfileEntry = new WifiProfileEntry { Profile = profile, SSID = sSID, Authentication = authentication, PassPhrase = passPhrase, Interface = wifiInterface, State = state.ToString() }; wifiProfileEntries.Add(CurrentWifiProfileEntry); } else { WriteError($"WlanGetProfile() failed: {retGetProfile}"); } WlanProfileInfoPtr = (IntPtr)(WlanProfileInfoPtr.ToInt64() + Marshal.SizeOf(WlanProfileInfo)); } WlanFreeMemory(ProfileListPtr); } else { WriteError($"WlanGetProfileList() failed: {retGetProfileList}"); } //info WlanInterfaceInfoPtr = (IntPtr)(WlanInterfaceInfoPtr.ToInt64() + Marshal.SizeOf(WlanInterfaceInfo)); } //WlanFree WlanFreeMemory(InterfaceListPtr); } else { WriteError($"WlanEnumInterfaces() failed: {retWlanEnum}"); yield break; } var retClose = WlanCloseHandle(ClientHandle, IntPtr.Zero); if (ret != Interop.Win32Error.Success) { WriteError($"WlanCloseHandle() failed: {retClose}"); } } else { WriteError($"WlanOpenHandle() failed: {ret}"); yield break; } yield return(new WifiProfileDTO(numberOfInterfaces, numberOfProfiles, wifiProfileEntries)); }
public WLAN_INTERFACE_INFO_LIST(IntPtr pList) { // The first 4 bytes are the number of WLAN_INTERFACE_INFO structures. dwNumberofItems = Marshal.ReadInt32(pList, 0); // The next 4 bytes are the index of the current item in the unmanaged API. dwIndex = Marshal.ReadInt32(pList, 4); // Construct the array of WLAN_INTERFACE_INFO structures. InterfaceInfo = new WLAN_INTERFACE_INFO[dwNumberofItems]; for (int i = 0; i < dwNumberofItems; i++) { // The offset of the array of structures is 8 bytes past the beginning. // Then, take the index and multiply it by the number of bytes in the // structure. // the length of the WLAN_INTERFACE_INFO structure is 532 bytes - this // was determined by doing a sizeof(WLAN_INTERFACE_INFO) in an // unmanaged C++ app. IntPtr pItemList = new IntPtr(pList.ToInt32() + (i * 532) + 8); // Construct the WLAN_INTERFACE_INFO structure, marshal the unmanaged // structure into it, then copy it to the array of structures. WLAN_INTERFACE_INFO wii = new WLAN_INTERFACE_INFO(); wii = (WLAN_INTERFACE_INFO)Marshal.PtrToStructure(pItemList, typeof(WLAN_INTERFACE_INFO)); InterfaceInfo[i] = wii; } }
public WLAN_INTERFACE_INFO_LIST(IntPtr pList) { NumberOfItems = Marshal.ReadInt32(pList, 0); Index = Marshal.ReadInt32(pList, 4); InterfaceInfo = new WLAN_INTERFACE_INFO[NumberOfItems]; for (int i = 0; i < NumberOfItems; i++) { IntPtr pItemList = new IntPtr(pList.ToInt32() + (i * 284)); WLAN_INTERFACE_INFO wii = new WLAN_INTERFACE_INFO(); byte[] intGuid = new byte[16]; for (int j = 0; j < 16; j++) { intGuid[j] = Marshal.ReadByte(pItemList, 8 + j); } wii.InterfaceGuid = new Guid(intGuid); //wii.InterfacePtr = new IntPtr(pItemList.ToInt32() + 8); wii.InterfaceDescription = Marshal.PtrToStringUni(new IntPtr(pItemList.ToInt32() + 24), 256).Replace("\0", ""); wii.State = (WLAN_INTERFACE_STATE)Marshal.ReadInt32(pItemList, 280); InterfaceInfo[i] = wii; } }
internal InterfaceInfo(WLAN_INTERFACE_INFO info) { Id = info.InterfaceGuid; Description = info.strInterfaceDescription; State = InterfaceStateConverter.Convert(info.isState); }
public WLAN_INTERFACE_INFO_LIST(IntPtr pList) { int iByteCount = 0; dwNumberOfItems = Marshal.ReadInt32(pList, iByteCount); iByteCount += Marshal.SizeOf(dwNumberOfItems.GetType()); dwIndex = Marshal.ReadInt32(pList, iByteCount); iByteCount += Marshal.SizeOf(dwIndex.GetType()); int ifListStartOffset = iByteCount; int ifListItemSize = Marshal.SizeOf(typeof(Int32)) * 5 + 2 * 256; // Int32*4 + WCHAR[256] + Int32 InterfaceInfo = new WLAN_INTERFACE_INFO[dwNumberOfItems]; for (int i = 0; i < dwNumberOfItems; i++) { // The offset of the array of structures is 8 bytes past the beginning. Then, take the index and multiply it by the number of bytes in the structure. IntPtr pItemList = new IntPtr(pList.ToInt32() + (i * ifListItemSize) + iByteCount); WLAN_INTERFACE_INFO wii = new WLAN_INTERFACE_INFO(); wii = (WLAN_INTERFACE_INFO)Marshal.PtrToStructure(pItemList, typeof(WLAN_INTERFACE_INFO)); InterfaceInfo[i] = wii; } }