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

John Savill

August 21, 2005

1 Min Read
ITPro Today logo

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, objWMISet objWMI = NothingSet 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.MacAddressNext

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

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like