How can I use Windows Management Instrumentation (WMI) to enumerate MAC addresses on a machine?

A. You can enumerate a machine's list of network adapters and find the associated MAC address. The following sample code, which you can download here, prints out the network adapter name and the MAC address.

Dim objNetworkAdapters, objAdapter, objWMI

Set objWMI = Nothing
Set objWMI = GetObject("winmgmts:")

' Get a list of IP-enabled adapters.
Set objNetworkAdapters = objWMI.ExecQuery("select * from Win32_NetworkAdapterConfiguration where IPEnabled = 1")

For Each objAdapter In objNetworkAdapters
      wscript.echo "Network adapter: " & objAdapter.Caption & " has MAC address " & objAdapter.MacAddress
Next

Here's a sample execution showing two adapters on the machine: D:\temp>cscript getmac.vbs Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. Network adapter: \[00000009\] Broadcom 570x Gigabit Integrated Controller has MAC address 00:0F:1F:25:DC:76 Network adapter: \[00000014\] Intel(R) PRO/Wireless 2200BG Network Connection has MAC address 00:0E:35:6E:2C:B4

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish