public static WlanConnectionInfo GetCurrentConnection(Guid guid) { uint num; uint num1 = 0; IntPtr zero = IntPtr.Zero; WlanConnectionInfo wlanConnectionInfo = null; if (WlanApiWrapper.WlanOpenHandle(2, IntPtr.Zero, out num1, out zero) == 0) { IntPtr intPtr = IntPtr.Zero; if (WlanApiWrapper.WlanQueryInterface(zero, guid, WlanApiWrapper.WLAN_INTF_OPCODE.wlan_intf_opcode_current_connection, IntPtr.Zero, out num, ref intPtr, IntPtr.Zero) == 0) { WlanApiWrapper.WLAN_CONNECTION_ATTRIBUTES structure = (WlanApiWrapper.WLAN_CONNECTION_ATTRIBUTES)Marshal.PtrToStructure(intPtr, typeof(WlanApiWrapper.WLAN_CONNECTION_ATTRIBUTES)); WlanConnectionInfo wlanConnectionInfo1 = new WlanConnectionInfo() { State = structure.isState, ConnectionMode = structure.wlanConnectionMode, ProfileName = structure.strProfileName }; wlanConnectionInfo = wlanConnectionInfo1; if (intPtr != IntPtr.Zero) { WlanApiWrapper.WlanFreeMemory(intPtr); } } WlanApiWrapper.WlanCloseHandle(zero, IntPtr.Zero); } return(wlanConnectionInfo); }
public static IEnumerable <WlanInterfaceInfo> EnumInterfaces() { uint num = 0; IntPtr zero = IntPtr.Zero; if (WlanApiWrapper.WlanOpenHandle(2, IntPtr.Zero, out num, out zero) == 0) { IntPtr intPtr = IntPtr.Zero; if (WlanApiWrapper.WlanEnumInterfaces(zero, IntPtr.Zero, out intPtr) == 0) { int num1 = Marshal.ReadInt32(intPtr, 0); Marshal.ReadInt32(intPtr, 4); for (int i = 0; i < num1; i++) { IntPtr intPtr1 = new IntPtr(intPtr.ToInt32() + i * 532 + 8); WlanApiWrapper.WLAN_INTERFACE_INFO structure = (WlanApiWrapper.WLAN_INTERFACE_INFO)Marshal.PtrToStructure(intPtr1, typeof(WlanApiWrapper.WLAN_INTERFACE_INFO)); WlanInterfaceInfo wlanInterfaceInfo = new WlanInterfaceInfo() { Guid = structure.InterfaceGuid, Description = structure.strInterfaceDescription, State = structure.isState }; yield return(wlanInterfaceInfo); } if (intPtr != IntPtr.Zero) { WlanApiWrapper.WlanFreeMemory(intPtr); } } WlanApiWrapper.WlanCloseHandle(zero, IntPtr.Zero); } }