Here is the VB.NET equivalent of Willy Denoyette's C# wrapper class for the
GetAdaptersInfo() API. The GetMacAddress() is the method that uses the API
(as appeared in his original post).
Hope this helps.
Public Class IpHelper
<DllImport("IphlpApi", CharSet:=CharSet.Ansi, SetLastError:=True),
System.Security.SuppressUnmanagedCodeSecurityAttribute()> _
Public Shared Function GetAdaptersInfo(ByVal pAdapterInfo As IntPtr, ByRef
pOutBufLen As Integer) As Integer
End Function
Structure _IP_ADDR_STRING
Private [Next] As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpAddress As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Friend IpMask As String
Private Context As Integer
End Structure '_IP_ADDR_STRING
<StructLayout(LayoutKind.Sequential)> _
Structure _IP_ADAPTER_INFO
Friend [Next] As IntPtr
Private ComboIndex As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=260)> _
Friend AdapterName() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=132)> _
Friend Description() As Byte
Friend AddressLength As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
Friend Address() As Byte
Private Index As System.UInt32
Private Type As System.UInt32
Private DhcpEnabled As Integer
Private CurrentIpAddress As IntPtr
Friend IpAddressList As _IP_ADDR_STRING
Friend GatewayList As _IP_ADDR_STRING
Friend DhcpServer As _IP_ADDR_STRING
Private HaveWins As Boolean
Friend PrimaryWinsServer As _IP_ADDR_STRING
Friend SecondaryWinsServer As _IP_ADDR_STRING
Private LeaseObtained As Integer
Private LeaseExpires As Integer
End Structure
Public Function GetMacAddress() As ArrayList
Dim pAdapterInfo As IntPtr = IntPtr.Zero
Dim pOutBufLen As Integer = 0
Dim ad As New ArrayList
Dim ipinfo As New _IP_ADAPTER_INFO
Dim ret As Integer = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
pAdapterInfo = Marshal.AllocHGlobal(pOutBufLen)
ret = GetAdaptersInfo(pAdapterInfo, pOutBufLen)
ipinfo = CType(Marshal.PtrToStructure(pAdapterInfo,
GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
While Not ipinfo.Next.op_Equality(ipinfo.Next, IntPtr.Zero)
ipinfo = CType(Marshal.PtrToStructure(ipinfo.Next,
GetType(_IP_ADAPTER_INFO)), _IP_ADAPTER_INFO)
ad.Add(ipinfo.Address)
End While
Marshal.FreeHGlobal(pAdapterInfo)
Return ad
End Function 'GetMacAddress
End Class
"Marni" <www> wrote in message If anyone can do a declare staement for me it will be very
helpfull.
Shiva said:
Hi,
You may want to use WMI (System.Management namespace) to get network adapter
info.
If you still want to use the same API, this thread has an example (in
C#)
by
Willy Denoyette. Check it out: