Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Getting MAC Addresses
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

JerryP
Hi Group,

has anyone of you tried to discover MAC addresses on your local LAN with VB
? are there any pointers on how to
start or even code snippets ???

Thanks!

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Patrick Steele [MVP] (VIP)
In article <e5TaqA47BHA.2288@tkmsftngp03> (from JerryP
<Click here to reveal e-mail address>),
[Original message clipped]

http://groups.google.com/groups?selm=eeeD%24NrxAHA.2188%40tkmsftngp02

--
Patrick Steele
Microsoft .NET MVP
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Khoj Ladha[MS]
Here is the VB.net code which displays the information of ipconfig /all
which includes the MAC address of the machine. This will work on Windows 98
and higher and windows 2000 and higher. It makes use of Ip helper api's
GetNetworkParams and GetAdapterInfo() api

Here is the code
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-----------------------------------------
'=====================================================================
' File: IPConfig.vb

' Summary: Demonstrates how to programatically retrieve IP configuration
'             information by invoking native win32 API's using unmanaged code
'             in C#. The output is very similar to IPCONFIG.EXE utility.

'---------------------------------------------------------------------
' This file is part of the Microsoft .NET Framework SDK Code Samples.

' Copyright (C) 2000 Microsoft Corporation. All rights reserved.

'This source code is intended only as a supplement to Microsoft
'Development Tools and/or on-line documentation. See these other
'materials for detailed information regarding Microsoft code samples.

'THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
'KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
'IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'PARTICULAR PURPOSE.
'=====================================================================

'Add the following namespaces
Imports System
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Threading
Imports Microsoft.VisualBasic.Constants
Imports Microsoft.VisualBasic.Conversion

'Constants used in the program as defined in IPExport.h and WinError.h
Public Class IPConfigConst
Public Const MAX_ADAPTER_NAME As Integer = 128
Public Const MAX_HOSTNAME_LEN As Integer = 128
Public Const MAX_DOMAIN_NAME_LEN As Integer = 128
Public Const MAX_SCOPE_ID_LEN As Integer = 256
Public Const MAX_ADAPTER_DESCRIPTION_LENGTH As Integer = 128
Public Const MAX_ADAPTER_NAME_LENGTH As Integer = 256
Public Const MAX_ADAPTER_ADDRESS_LENGTH As Integer = 8
Public Const DEFAULT_MINIMUM_ENTITIES As Integer = 32

Public Const ERROR_BUFFER_OVERFLOW As Integer = 111
Public Const ERROR_SUCCESS As Integer = 0
End Class

'Different Adapter types as defined in IPifcons.h
Public Class IPAdapterTypes
Public Const MIB_IF_TYPE_OTHER As Integer = 1
Public Const MIB_IF_TYPE_ETHERNET As Integer = 6
Public Const MIB_IF_TYPE_TOKENRING As Integer = 9
Public Const MIB_IF_TYPE_FDDI As Integer = 15
Public Const MIB_IF_TYPE_PPP As Integer = 23
Public Const MIB_IF_TYPE_LOOPBACK As Integer = 24
Public Const MIB_IF_TYPE_SLIP As Integer = 28
End Class

'typedef struct _IP_ADAPTER_INFO
'{
'    struct _IP_ADAPTER_INFO* Next;
'    DWORD ComboIndex;
'    char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
'    char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
'    UINT AddressLength;
'    BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
'    DWORD Index;
'    UINT Type;
'    UINT DhcpEnabled;
'    PIP_ADDR_STRING CurrentIpAddress;
'    IP_ADDR_STRING IpAddressList;
'    IP_ADDR_STRING GatewayList;
'    IP_ADDR_STRING DhcpServer;
'    BOOL HaveWins;
'    IP_ADDR_STRING PrimaryWinsServer;
'    IP_ADDR_STRING SecondaryWinsServer;
'    time_t LeaseObtained;
'    time_t LeaseExpires;
'}

'declared as structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure IPAdapterInfo

Public NextPointer As IntPtr
Public ComboIndex As Integer

<MarshalAs(UnmanagedType.ByValTStr, _
SizeConst:=IPConfigConst.MAX_ADAPTER_NAME_LENGTH + 4)> _
Public AdapterName As String

<MarshalAs(UnmanagedType.ByValTStr, _
SizeConst:=IPConfigConst.MAX_ADAPTER_DESCRIPTION_LENGTH + 4)> _
Public Description As String

Public AddressLength As Integer

<MarshalAs(UnmanagedType.ByValArray, _
SizeConst:=IPConfigConst.MAX_ADAPTER_ADDRESS_LENGTH)> _
Public Address() As Byte

Public Index As Integer
Public Type As Integer
Public DhcpEnabled As Integer
Public CurrentIPAddress As IntPtr
Public IPAddressList As IPAddrString
Public GatewayList As IPAddrString
Public DhcpServer As IPAddrString
Public HaveWins As Boolean
Public PrimaryWinsServer As IPAddrString
Public SecondaryWinsServer As IPAddrString
Public LeaseObtained As Integer
Public LeaseExpires As Integer
End Structure

'typedef struct _IP_ADDR_STRING
'{
'    struct _IP_ADDR_STRING* Next;
'    IP_ADDRESS_STRING IpAddress;
'    IP_MASK_STRING IpMask;
'    DWORD Context;
'}

'declared as structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure IPAddrString

Public NextPointer As IntPtr

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4 * 4)> _
Public IPAddressString As String

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4 * 4)> _
Public IPMaskString As String

Public Context As Integer
End Structure

'typedef struct _IP_ADAPTER_INDEX_MAP
'{
'    ULONG Index // adapter index
'    WCHAR Name [MAX_ADAPTER_NAME]; // name of the adapter
'}

'declared as structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure IPAdapterIndexMap

Public Index As Integer

<MarshalAs(UnmanagedType.ByValTStr, _
SizeConst:=IPConfigConst.MAX_ADAPTER_NAME)> _
Public Name As String
End Structure

'typedef struct _IP_INTERFACE_INFO
'{
'    LONG NumAdapters; // number of adapters in array
'    IP_ADAPTER_INDEX_MAP Adapter[1]; // adapter indices and names
'}

'declared as structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure IPInterfaceInfo

Public NumAdapters As Integer
Public Adapter As IPAdapterIndexMap
End Structure

'typedef struct
'{
'    char HostName[MAX_HOSTNAME_LEN + 4] ;
'    char DomainName[MAX_DOMAIN_NAME_LEN + 4];
'    PIP_ADDR_STRING CurrentDnsServer;
'    IP_ADDR_STRING DnsServerList;
'    UINT NodeType;
'    char ScopeId[MAX_SCOPE_ID_LEN + 4];
'    UINT EnableRouting;
'    UINT EnableProxy;
'    UINT EnableDns;
'}

'declared as class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Class FixedInfo

<MarshalAs(UnmanagedType.ByValTStr, _
SizeConst:=IPConfigConst.MAX_HOSTNAME_LEN + 4)> _
Public HostName As String

<MarshalAs(UnmanagedType.ByValTStr, _
SizeConst:=IPConfigConst.MAX_DOMAIN_NAME_LEN + 4)> _
Public DomainName As String

Public CurrentServerList As IntPtr
Public DnsServerList As IPAddrString
Public NodeType As Integer

<MarshalAs(UnmanagedType.ByValTStr, _
SizeConst:=IPConfigConst.MAX_SCOPE_ID_LEN + 4)> _
Public ScopeId As String

Public EnableRouting As Integer
Public EnableProxy As Integer
Public EnableDns As Integer
End Class

'LibWrap is a class which contains invokation of the Win32 API's using
DllImport
Public Class LibWrap

'DWORD GetNetworkParams(PFIXED_INFO pFixedInfo,PULONG pOutBufLen);
Declare Auto Function GetNetworkParams Lib "Iphlpapi.dll" _
(ByVal PFixedInfoBuffer As Byte(), ByRef size As Integer) As Integer

'DWORD GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo,PULONG pOutBufLen);
Declare Auto Function GetAdaptersInfo Lib "Iphlpapi.dll" _
(ByVal PAdapterInfoBuffer As Byte(), ByRef size As Integer) As Integer

'DWORD GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG
dwOutBufLen);
Declare Auto Function GetInterfaceInfo Lib "Iphlpapi.dll" _
(ByVal PIfTableBuffer As Byte(), ByRef size As Integer) As Integer

'copymemory function has many declarations depending on the type of
parameters
'VOID CopyMemory(PVOID Destination, CONST VOID* Source,
'SIZE_T Length);

'copying from Byte[] to FixedInfo class. Passes the class as In/Out
Parameter
Declare Auto Sub CopyMemoryFixedInfo Lib "Kernel32.dll" Alias
"CopyMemory" _
(<Out()> ByVal dest As FixedInfo, _
ByVal source As Byte(), ByVal size As Integer)

'copying from IntPtr to IPAddrString structure
Declare Auto Sub CopyMemoryIPAddrString Lib "Kernel32.dll" Alias
"CopyMemory" _
(ByRef dest As IPAddrString, ByVal source As IntPtr, ByVal size As
Integer)

'copying from Byte[] to IPAdapterInfo structure
Declare Auto Sub CopyMemoryIPAdapterInfo Lib "Kernel32.dll" Alias
"CopyMemory" _
(ByRef dest As IPAdapterInfo, ByVal source As Byte(), ByVal
size As Integer)

'copying from IntPtr to IPAdapterInfo structure
Declare Auto Sub CopyMemoryIPAdapterInfoP Lib "Kernel32.dll" Alias
"CopyMemory" _
(ByRef dest As IPAdapterInfo, ByVal source As IntPtr, ByVal size As
Integer)

'copying from byte to int variable
Declare Auto Sub CopyMemoryInt Lib "Kernel32.dll" Alias "CopyMemory" _
(ByRef dest As Integer, ByRef source As Byte, ByVal size As Integer)

'copying from byte to IPAdapterIndexMap structure
Declare Auto Sub CopyMemoryIPAdapterIndexMap Lib "Kernel32.dll" Alias
"CopyMemory" _
(ByRef dest As IPAdapterIndexMap, ByRef source As Byte, ByVal size
As Integer)

'DWORD IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
Declare Auto Function IpReleaseAddress Lib "Iphlpapi.dll" _
(ByRef AdapterInfo As IPAdapterIndexMap) As Integer

'DWORD IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
Declare Auto Function IpRenewAddress Lib "Iphlpapi.dll" _
(ByRef AdapterInfo As IPAdapterIndexMap) As Integer

End Class

Public Class App

'define usage of the program
Public Shared Sub usage()
Console.WriteLine("Usage: Iprenew [ -l ] [ -r<index id> ] [
-n<index id>]")
Console.WriteLine(vbTab & "-l List adapters with corresponding
index ID and other information")
Console.WriteLine(vbTab & "-r Release IP address for adapter index
ID")
Console.WriteLine(vbTab & "-n Renew IP address for adapter index
ID")
End Sub

Public Shared Sub Main(ByVal args() As String)

'used while invoking win32 API's
Dim retValue As Integer
Dim size As Integer

'for command line arguments
Dim optList As Boolean = False
Dim optRelease As Boolean = False
Dim optRenew As Boolean = False
Dim temp As String

'to check if adapter is of type Ethernet Adapter
Dim ifEthernet As Boolean = False

'index for which address is released or renewed
Dim index As Integer = 0

'local variable
Dim i As Integer

If args.Length = 0 Then
usage()
Return
End If

'checking for command line arguments    
For i = 0 To args.Length - 1
If ((args(i).Chars(0) = "-") Or (args(i).Chars(0) = "/")) Then

Select Case args(i).Chars(1)
Case "l"
'to list all adapter information
optList = True

Case "r"
'to release IP address for given index
optRelease = True
If (args(i).Length >= 2) Then
temp = args(i).Substring(2, args(i).Length - 2)
index = Int32.Parse(temp)
Else
usage()
End If

Case "n"
'to renew IP address for given index
optRenew = True
If (args(i).Length >= 2) Then
temp = args(i).Substring(2, args(i).Length - 2)
index = Int32.Parse(temp)
Else
usage()
End If

Case Else
usage()
Return
End Select

End If
Next i

If (optRelease Or optRenew) Then
Console.WriteLine("Given Adapter Index : " & index)
End If

'print all the network adapter information
If (optList) Then

'since Byte[] is class, we can pass Nothing as parameter
'to get the required buffer size
retValue = LibWrap.GetNetworkParams(Nothing, size)

'checking for error
If (retValue <> IPConfigConst.ERROR_SUCCESS And _
retValue <> IPConfigConst.ERROR_BUFFER_OVERFLOW) Then
Console.WriteLine("Error invoking GetNetworkParams() : " +
retValue)
Return
End If

'creating a buffer with required size
Dim PFixedInfoBuffer(size) As Byte

'Invoking GetNetworkParams()
retValue = LibWrap.GetNetworkParams(PFixedInfoBuffer, size)

If (retValue <> IPConfigConst.ERROR_SUCCESS) Then
Console.WriteLine("Error invoking GetNetworkParams() " +
retValue)
Return
End If

Dim PFixedInfo As New FixedInfo()

'copy from the Buffer to the FIXED_INFO structure
LibWrap.CopyMemoryFixedInfo(PFixedInfo, PFixedInfoBuffer, _
Marshal.SizeOf(PFixedInfo))

Console.WriteLine("Windows IP Configuration:")
Console.WriteLine()
Console.WriteLine(vbTab & vbTab & "HostName....................
: " + _
PFixedInfo.HostName)
Console.WriteLine(vbTab & vbTab & "DomainName..................
: " + _
PFixedInfo.DomainName)

Dim List As New IPAddrString()
Dim ListNext As New IntPtr()

'Linked list of IP_ADDR_STRING structures that
'specify the set of DNS servers used by the local computer.
Console.Write(vbTab & vbTab & "DnsServerList............... : ")
Console.WriteLine(PFixedInfo.DnsServerList.IPAddressString)
ListNext = PFixedInfo.DnsServerList.NextPointer
While (ListNext.ToInt32() <> 0)
LibWrap.CopyMemoryIPAddrString(List, ListNext,
Marshal.SizeOf(List))
Console.WriteLine(vbTab & vbTab & _
vbTab & vbTab & vbTab & _
vbTab & List.IPAddressString)
ListNext = List.NextPointer
End While
Select Case (PFixedInfo.NodeType)

Case 1
Console.WriteLine(vbTab & vbTab & "Node
Type................... : Broadcast")
Case 2
Console.WriteLine(vbTab & vbTab & "Node
Type................... : Peer to Peer")
Case 4
Console.WriteLine(vbTab & vbTab & "Node
Type................... : Mixed")
Case 8
Console.WriteLine(vbTab & vbTab & "Node
Type................... : Hybrid")
Case Else
Console.WriteLine(vbTab & vbTab & "Node
Type................... : Unknown")
End Select

If (PFixedInfo.EnableRouting <> 0) Then
Console.WriteLine(vbTab & vbTab & "IP Routing
Enabled.......... : Yes")
Else
Console.WriteLine(vbTab & vbTab & "IP Routing
enabled.......... : No")
End If

If (PFixedInfo.EnableProxy <> 0) Then
Console.WriteLine(vbTab & vbTab & "WINS Proxy
Enabled.......... : Yes")
Else
Console.WriteLine(vbTab & vbTab & "WINS Proxy not
enabled...... : No")
End If

If (PFixedInfo.EnableDns <> 0) Then
Console.WriteLine(vbTab & vbTab & "NetBIOS Resolution Uses
DNS : Yes")
Else
Console.WriteLine(vbTab & vbTab & "NetBIOS Resolution Uses
DNS : No")
End If
Console.WriteLine()
Console.WriteLine()

're-intializing the size
size = 0

'since Byte[] is class, we can pass null as parameter
'to get the required buffer size
retValue = LibWrap.GetAdaptersInfo(Nothing, size)

'checking for error
If (retValue <> IPConfigConst.ERROR_SUCCESS And _
retValue <> IPConfigConst.ERROR_BUFFER_OVERFLOW) Then
Console.WriteLine("Error invoking GetAdaptersInfo() : " +
retValue)
Return
End If

Dim IPAdapterInfoBuffer(size) As Byte
Dim PAdapterInfo As New IPAdapterInfo()

'Invoking GetAdapterInfo()
retValue = LibWrap.GetAdaptersInfo(IPAdapterInfoBuffer, size)

'checking for error
If (retValue <> IPConfigConst.ERROR_SUCCESS) Then
Console.WriteLine("Error invoking GetAdaptersInfo() : " +
retValue)
Return
End If

'copy from the Buffer to the IP_ADAPTER_INFO structure
LibWrap.CopyMemoryIPAdapterInfo(PAdapterInfo,
IPAdapterInfoBuffer, _
Marshal.SizeOf(PAdapterInfo))

'pointing next block for IP_ADAPTER_INFO
Dim AdapterInfoNext As New IntPtr()

Do
Select Case PAdapterInfo.Type
Case IPAdapterTypes.MIB_IF_TYPE_ETHERNET
Console.Write("Ethernet adapter ")
ifEthernet = True

Case IPAdapterTypes.MIB_IF_TYPE_TOKENRING
Console.Write("Token Ring adapter ")

Case IPAdapterTypes.MIB_IF_TYPE_FDDI
Console.Write("FDDI adapter ")

Case IPAdapterTypes.MIB_IF_TYPE_PPP
Console.Write("PPP adapter ")

Case IPAdapterTypes.MIB_IF_TYPE_LOOPBACK
Console.Write("Loopback adapter ")

Case IPAdapterTypes.MIB_IF_TYPE_SLIP
Console.Write("Slip adapter ")

Case IPAdapterTypes.MIB_IF_TYPE_OTHER
Console.Write("Other type of adapter")

Case Else
Console.Write("Other adapter ")
End Select
Console.WriteLine(PAdapterInfo.AdapterName & vbCr)
Console.WriteLine(vbTab & vbTab & "Adapter
Index............... : " + _
PAdapterInfo.Index.ToString())
Console.WriteLine(vbTab & vbTab &
"Description................. : " + _
PAdapterInfo.Description)
Console.Write(vbTab & vbTab & "Physical Address............
: ")

Dim l As Integer
For l = 0 To PAdapterInfo.AddressLength - 1
If (l = PAdapterInfo.AddressLength - 1) Then
Console.WriteLine(Hex(PAdapterInfo.Address(l)))
Else
Console.Write(Hex(PAdapterInfo.Address(l)) + "-")
End If
Next l

If (PAdapterInfo.DhcpEnabled <> 0) Then
Console.WriteLine(vbTab & vbTab & "DHCP
Enabled................ : Yes")
Else
Console.WriteLine(vbTab & vbTab & "DHCP
Enabled................ : No")
End If

'IP Address list
Console.WriteLine(vbTab & vbTab & "IP
Address.................. : " + _
PAdapterInfo.IPAddressList.IPAddressString)
Console.WriteLine(vbTab & vbTab & "Subnet
Mask................. : " + _
PAdapterInfo.IPAddressList.IPMaskString)
Dim PIPList As New IntPtr()
PIPList = PAdapterInfo.IPAddressList.NextPointer
Dim IPAddressList As New IPAddrString()
While (PIPList.ToInt32() <> 0)
LibWrap.CopyMemoryIPAddrString(IPAddressList, PIPList, _
Marshal.SizeOf(IPAddressList))
Console.WriteLine(vbTab & vbTab & "IP
Address.................. : " _
+ IPAddressList.IPAddressString)
Console.WriteLine(vbTab & vbTab & "Subnet
Mask................. : " _
+ IPAddressList.IPMaskString)
PIPList = IPAddressList.NextPointer
End While

'Gateway List                    
Console.WriteLine(vbTab & vbTab & " Default
Gateway............. : " + PAdapterInfo.GatewayList.IPAddressString)
Dim PGateway As New IntPtr()
PGateway = PAdapterInfo.GatewayList.NextPointer
Dim IPGatewayList As New IPAddrString()
While (PGateway.ToInt32 <> 0)
LibWrap.CopyMemoryIPAddrString(IPGatewayList, PGateway,
Marshal.SizeOf(IPGatewayList))
Console.WriteLine(vbTab & vbTab & "Gateway
Address............. : " + IPGatewayList.IPAddressString)
PGateway = IPGatewayList.NextPointer
End While

Console.WriteLine(vbTab & vbTab & "DHCP
Server................. : " + PAdapterInfo.DhcpServer.IPAddressString)
Console.WriteLine(vbTab & vbTab & "Primary WINS
Server......... : " + PAdapterInfo.PrimaryWinsServer.IPAddressString)
Console.WriteLine(vbTab & vbTab & "Gateway
Address............. : " + PAdapterInfo.SecondaryWinsServer.IPAddressString)

'date and time when Lease is obtained and expired
If (ifEthernet) Then

Dim LeaseObt = New DateTime(1970, 1, 1)
Dim LeaseExp = New DateTime(1970, 1, 1)
LeaseObt =
LeaseObt.AddSeconds(PAdapterInfo.LeaseObtained)
LeaseExp =
LeaseExp.AddSeconds(PAdapterInfo.LeaseExpires)

Console.WriteLine(vbTab & vbTab & "Lease
Obtained.............. : " + LeaseObt.ToString())
Console.WriteLine(vbTab & vbTab & "Lease
Expires............... : " + LeaseExp.ToString())
End If

'setting it to next Adapter information
AdapterInfoNext = PAdapterInfo.NextPointer

If (AdapterInfoNext.ToInt32 <> 0) Then
LibWrap.CopyMemoryIPAdapterInfoP(PAdapterInfo,
AdapterInfoNext, Marshal.SizeOf(PAdapterInfo))
End If
Console.WriteLine()
Console.WriteLine()

Loop While (AdapterInfoNext.ToInt32 <> 0)
'Depending on the number of adapters
End If

'Re-initializing the size
size = 0

'if IP Release or Renew
If (optRelease Or optRenew) Then

'since Byte[] is class, we can pass null as parameter
'to get the required buffer size
LibWrap.GetInterfaceInfo(Nothing, size)

'Checking for error
If (retValue <> IPConfigConst.ERROR_SUCCESS And _
retValue <> IPConfigConst.ERROR_BUFFER_OVERFLOW) Then
Console.WriteLine("Error invoking GetInterfaceInfo() : " +
retValue)
Return
End If

Dim PIfTableBuffer(size) As Byte
Dim PIfTable As New IPInterfaceInfo()

'invoking GetInterfaceInfo()
retValue = LibWrap.GetInterfaceInfo(PIfTableBuffer, size)

'checking for error
If (retValue <> IPConfigConst.ERROR_SUCCESS) Then
Console.WriteLine("Error Value from GetInterfaceInfo(): " +
retValue)
Return
End If

Dim NumAdapters As Integer = 0
Dim byteCount As Integer = 0

'copy from PIfTableBuffer to NumAdapters
LibWrap.CopyMemoryInt(NumAdapters, PIfTableBuffer(byteCount), 4)

byteCount = byteCount + 4

If (NumAdapters = 0) Then
Console.WriteLine("No Adpaters found")
Return
End If

Dim PIPAdapterIndexMap As New IPAdapterIndexMap()

For i = 0 To NumAdapters - 1
'copy from PIfTableBuffer to IP_ADAPTER_INDEX_MAP Structure
LibWrap.CopyMemoryIPAdapterIndexMap(PIPAdapterIndexMap,
PIfTableBuffer(byteCount), Marshal.SizeOf(PIPAdapterIndexMap))
byteCount = byteCount + Marshal.SizeOf(PIPAdapterIndexMap)

'checking for index number
If (index = PIPAdapterIndexMap.Index) Then

'if IP Release
If (optRelease) Then

retValue =
LibWrap.IpReleaseAddress(PIPAdapterIndexMap)
If (retValue <> IPConfigConst.ERROR_SUCCESS) Then
Console.WriteLine("Error invoking IPRelease: "
& retValue)
Return
End If

Console.WriteLine("IP Address Released....")
End If

'if IP Renew
If (optRenew) Then

retValue =
LibWrap.IpRenewAddress(PIPAdapterIndexMap)
If (retValue <> IPConfigConst.ERROR_SUCCESS) Then
Console.WriteLine("Error invoking IPRenew: " &
retValue)
Return
End If

Console.WriteLine("IP Address Renewed....")
End If
End If

Next i
End If

End Sub

End Class

----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------------------------------
Use the following syntax to get the result
<name of the exe>.exe -l

Thanks,

Khoj Ladha

Microsoft Developer Support
Microsoft Support Site http://support.microsoft.com/directory/
Search Knowledge Base
http://search.support.microsoft.com/kb/c.asp?fr=0&SD=GN&LN=EN-US
This posting is provided "AS IS" with no warranties, and confers no rights.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
JerryP
GOOD ANSWER
Thanks for you help - but I need the MAC's of the NIC's on the LAN - not my
own......

"Khoj Ladha[MS]" <Click here to reveal e-mail address> wrote in message
news:$MxWIN87BHA.1532@cpmsftngxa08...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer... (2 votes from other users already)
 
 
    
yao liang
I had tried to copy the code and run it... i getting a lot of errors ..
It any possible way, i can download the source code you posted?

Thanks,

--------------------------------
From: yao liang
Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
JerryP
Patrick - thanks,

but I dont need the MAC Address of the NIC's installed in the local system -
I need the MAC's that are arround
my system - I need to discover who is on the lan - I cant use a ping - arp
way as I dont know the IP Addresses that could be used.

Maybe another hint ?

"Patrick Steele [MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Patrick Steele [MVP] (VIP)
In article <OJJk3$A8BHA.2044@tkmsftngp04> (from JerryP
<Click here to reveal e-mail address>),
[Original message clipped]

Hmmmm.... Not sure about this. I don't know of any "native" or "built-
in" way of access NIC information across the LAN. You'd probably need
something running on each machine that exposes the NIC information and a
central machine that would talk to that program across all the machines.

There may be off-the-shelf products to do this for you (network
monitoring type stuff).

--
Patrick Steele
Microsoft .NET MVP
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
News
Try using some of the WMI [windows management instrumentation API]
functionality.

Pre-reqs would be, to have WMI service running on machine you have NIC on
[mostly its automatic and starts automatically, its part of standard w2k
install]. I don't think this will work with Win9Xs. Only W2k and higher
versions.

Then using WMI objects query for the computer name to get connected to the
computer with NIC.

From that point on you can get any kind of information you need that is
supported by WMI. The WMI is very powerful and will have something that will
work for you. I once wrote a small vb script to shutdown/restart remote
computers and collect IP addresses of computers on network.

I think recently there was an article on msdn on how to use WMI from .NET
code. You might want to check the recent articles section of msdn. If not
then try downloading WMI sdk that has bunch of examples and code.

HTH.

"JerryP" <Click here to reveal e-mail address> wrote in message
news:OJJk3$A8BHA.2044@tkmsftngp04...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
Lance Wulfers
GOOD ANSWER
I am trying to do the same, retrieving the mac address of a node on the local network. There is an IPHLPAPI function called SendArp that should do the trick. I'm still trying to determine how to call it, but it looks like the correct function. If you get this working please let me know how you did it. Thanks...
--------------------------------
From: Lance Wulfers
Reply to this message...
Vote that this is a GOOD answer... (2 votes from other users already)
 
 
 
Microsoft.VisualBasic.Constants
Microsoft.VisualBasic.Conversion
System.Console
System.DateTime
System.Int32
System.IntPtr
System.Runtime.InteropServices.CharSet
System.Runtime.InteropServices.LayoutKind
System.Runtime.InteropServices.Marshal
System.Runtime.InteropServices.UnmanagedType
System.Type
System.Web.UI.MobileControls.List




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734