[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6030
  • Last Modified:

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?

0
Juliancito
Asked:
Juliancito
  • 6
  • 3
1 Solution
 
gecko_au2003Commented:
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
 
gecko_au2003Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
gecko_au2003Commented:
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
 
gecko_au2003Commented:
ok well in that case look at the first 2 url's I posted ;)
0
 
gecko_au2003Commented:
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
 
gecko_au2003Commented:
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now