<DllImport("iphlpapi.dll", EntryPoint:="GetAdaptersInfo", CharSet:=CharSet.Ansi)> _Private Shared FunctionGetAdaptersInfo( _ByVal pAdapterInfo As IntPtr, _ByRef pBufOutLen As UInt64) As Int32End Function
Sample Code:
Public SubGetAdapters() Dim structSize As Int32 = Marshal.SizeOf(GetType(IP_ADAPTER_INFO)) Dim pArray As IntPtr = Marshal.AllocHGlobal(structSize) Dim len As UInt64 = Convert.ToUInt64(structSize) Dim ret As Int32 = GetAdaptersInfo(pArray, len) If ret = 111 Then ' Buffer was too small, reallocate the correct size for the buffer. pArray = Marshal.ReAllocHGlobal(pArray,New IntPtr(Convert.ToInt64(len))) ret = GetAdaptersInfo(pArray, len) End If If ret = 0 Then ' Call succeeded Dim pEntry As IntPtr = pArray Do ' Retrieve the adapter info from the memory address. Dim Entry As IP_ADAPTER_INFO = CType(Marshal.PtrToStructure(pEntry, GetType(IP_ADAPTER_INFO)), IP_ADAPTER_INFO) pEntry = Entry.Next Loop Until IntPtr.op_Equality(pEntry, IntPtr.Zero) End If Marshal.FreeHGlobal(pArray)End Sub