take a look at this C# code, it may help:
using System;
using System.Collections;
using System.Runtime.InteropServices;
namespace AdapterInfoTest
{
///
/// Summary description for AdapterInfo.
///
publicsealedclassAdapterInfo
{
constint MAX_ADAPTER_NAME_LENGTH = 256;
constint MAX_ADAPTER_DESCRIPTION_LENGTH = 128;
constint MAX_ADAPTER_ADDRESS_LENGTH = 8;
constint ERROR_BUFFER_OVERFLOW = 111;
constint ERROR_SUCCESS = 0;
[DllImport('iphlpapi.dll', CharSet=CharSet.Ansi)]
privatestaticexternint GetAdaptersInfo(IntPtr pAdapterInfo, refInt64 pBufOutLen);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
privatestructIP_ADDRESS_STRING
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=16)]
publicstring Address;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
privatestructIP_ADDR_STRING
{
publicIntPtr Next;
publicIP_ADDRESS_STRING IpAddress;
publicIP_ADDRESS_STRING Mask;
publicInt32 Context;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
privatestructIP_ADAPTER_INFO
{
publicIntPtr Next;
publicInt32 ComboIndex;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAX_ADAPTER_NAME_LENGTH + 4)]
publicstring AdapterName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAX_ADAPTER_DESCRIPTION_LENGTH + 4)]
publicstring AdapterDescription;
publicUInt32 AddressLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=MAX_ADAPTER_ADDRESS_LENGTH)]
publicbyte [] Address; Screenshot mac ios.
publicInt32 Index;
publicUInt32 Type;
publicUInt32 DhcpEnabled;
publicIntPtr CurrentIpAddress;
publicIP_ADDR_STRING IpAddressList;
publicIP_ADDR_STRING GatewayList;
publicIP_ADDR_STRING DhcpServer;
publicbool HaveWins;
publicIP_ADDR_STRING PrimaryWinsServer;
publicIP_ADDR_STRING SecondaryWinsServer;
publicInt32 LeaseObtained;
publicInt32 LeaseExpires;
}
public AdapterInfo()
{
}
publicstaticAdapter[] GetAdaptersInfo()
{
Adapter[] adaptersList; Pdf mac master safe.
ArrayList adapters = newArrayList();
long structSize = Marshal.SizeOf( typeof( IP_ADAPTER_INFO ) );
IntPtr pArray = Marshal.AllocHGlobal((int) structSize );
int ret = GetAdaptersInfo(pArray, ref structSize );
if (ret ERROR_BUFFER_OVERFLOW ) // ERROR_BUFFER_OVERFLOW 111
{
// Buffer was too small, reallocate the correct size for the buffer.
pArray = Marshal.ReAllocHGlobal( pArray, newIntPtr (structSize) );
ret = GetAdaptersInfo( pArray, ref structSize );
} // if
if ( ret 0 )
{
// Call Succeeded
IntPtr pEntry = pArray;
do
{
// Retrieve the adapter info from the memory address
IP_ADAPTER_INFO entry = (IP_ADAPTER_INFO)Marshal.PtrToStructure( pEntry, typeof( IP_ADAPTER_INFO ));
Adapter adapter = newAdapter();
adapter.index = entry.Index.ToString();
adapter.name = entry.AdapterName;
adapter.description = entry.AdapterDescription;
adapter.ip = entry.IpAddressList.IpAddress.Address;
// MAC Address (data is in a byte[])
string tmpString = string.Empty;
for (int i = 0; i < entry.AddressLength ; i++)
{
tmpString += string.Format('{0:X2}', entry.Address);
}
adapter.macAddress = tmpString;
adapters.Add(adapter);
// Get next adapter (if any)
pEntry = entry.Next;
}
while( pEntry != IntPtr.Zero );
Marshal.FreeHGlobal(pArray);
adaptersList = newAdapter[adapters.Count];
adapters.CopyTo(adaptersList);
}
else
{
adaptersList = newAdapter[0];
Marshal.FreeHGlobal(pArray);
thrownewInvalidOperationException( 'GetAdaptersInfo failed with ' + ret );
}
return adaptersList;
}
}
publicclassAdapter
{
publicstring index;
publicstring name;
publicstring description;
publicstring ip;
publicstring macAddress;
}
}