How READ NIC (ethernet) physical address

The problem is simple:
I want to read MAC ADDRESS of my NIC (Network Interface)
(MAC ADDRESS = physical ADDRESS) (Not IP Address)

For example:

-->Dirección física. . . . . . . : 00-11-D8-58-B9-61   (this!!!!!!!!!)
DHCP habilitado . . . . . . . : No
Dirección IP. . . . . . . . . : 202.12.218.143
Máscara de subred . . . . . . : 255.255.255.248

Is there an API to get that info?

LVL 2
JuliancitoAsked:
Who is Participating?
 
Shane Russell2nd Line Desktop SupportCommented:
Take a look at these :

http://www.visualbasicforum.com/showthread.php?t=180606

http://www.utteraccess.com/forums/access/access2302370.html

Coded example :

Go to project --> References and check Microsoft Scripting Runtime , then click ok, then insert this code in to the form load event :

Private Sub Form_Load()
On Error Resume Next
Const wbemFlagReturnImmediately = &H10
Const wbemFlagForwardOnly = &H20
strComputer = "."

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      MsgBox "MAC Address for adapter " & objItem.Caption & ":  " & objItem.MACAddress
   Next
End Sub
0
 
Shane Russell2nd Line Desktop SupportCommented:
How to obtain remote mac address :

http://vbnet.mvps.org/index.html?code/network/macaddressremote.htm

How to obtain local mac address :

http://vbnet.mvps.org/index.html?code/network/macaddress.htm

There are plenty of other useful examples on that site and if you are still stuck there is always :

www.allapi.net

They have an API program called api guide which you can download for free and install and it has plenty of API Examples :)
0
 
sj_hicksCommented:
WMI contains all this information.  The below VBScript will display the MAC address for all installed network adapters.

On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      WScript.Echo "MACAddress: " & objItem.MACAddress
   Next
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Shane Russell2nd Line Desktop SupportCommented:
Here is another example from that site that enumerates through all network adaptors and retrieves each mac address :

http://vbnet.mvps.org/code/network/netbiosenumlana.htm

Anyway I will stay subcribed to this questoin as it looks useful :)
0
 
sj_hicksCommented:
Hi gecko_au2003, just thought you might be interested:  If you use VB.NET to hook into the WMI provider in the .NET framework, you can access this same information in a few lines of code rather than needing to make lengthy calls to APIs.  Of course if you are programming for older OSes without WMI installed then this will not work.
0
 
Shane Russell2nd Line Desktop SupportCommented:
Is there anyway in your script to determine which lan adaptor the mac address is for because I tried to make it do a count and do it but it didnt work :

Dim i

On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
i= 0
i = i + 1
      WScript.Echo "MAC Address: " & i & "  " & objItem.MACAddress
   Next

I must be doing something wrong, as usual lol, btw thanks for that info with regards to WMI and vb.net ! Something to keep in mind for future reference :)
0
 
JuliancitoAuthor Commented:
SORRY: Im programming a simple exe in VB6 (not in .Net)
So I thank you very mutch for your help. i either want to resolve mac address by netbios resolution
I only want that system give me the info
:)
0
 
Shane Russell2nd Line Desktop SupportCommented:
ok well in that case look at the first 2 url's I posted ;)
0
 
Shane Russell2nd Line Desktop SupportCommented:
ooppps and the 3rd url as well, I only just remembered that as I scrolled up and saw it lol. I am sure that is what you need!
0
 
sj_hicksCommented:
gecko_au2003, to determine which adapter the MAC address is for, you can use the Caption property:

WScript.Echo "MAC Address for adapter " & objItem.Caption & ":  " & objItem.MACAddress

If you want more info on WMI properties, download a copy of Scriptomatic from Microsoft.  It'll even generate the code for you.

Juliancito, it is possible to access this information from WMI from VB6 - I've done it before but unfortunately don't have the code handy and cannot recall exactly how I did it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.