0

OK guys, this is not the usual easy to answer question the title may imply...

I need to get the MAC address from a machine running Windows (ranging from XP to Server2012). I have the following option that I can use:

1) getmac - Fine in general and also the format in which it returns the MAC address suits me, but it have caused me problems in the past.

2) WMIC - Also fine in general, but has also caused me issues in the
past and furthermore it is lagging in performance (especially on low spec machines).

3) ipconfing - Traditional way of retrieving it from the commands output. Could work but parsing the output could be cumbersome if more that one interfaces exist.

So the question is the following. What is the best alternative to all of the above in order to get a machine's MAC address. Keep in mind that I'll be invoking whatever utility through a shell script (whatever this adds up to the equation) and that I'm deploying on several different Windows editions (ranging from Professional to POS embedded).

Powershell is obviously out of the question since it is not supported by XP. Also the reason why I would like to avoid WMIC is 1) the fact that I have came across may bad installation (causing major issues) and 2) because some Windows editions (XP embedded for example) do not include it.

I have tried getting it by using the ARP table, but as far as I have seen it'll not list the MAC address of the local machine.

Any useful hints or ideas are welcome.

  • 1
    What sort of problems? Don't be vague. – Michael Hampton Nov 23 '16 at 20:28
  • WMIC isasues are mentioned. Getmac issues are revolve mainly on different outputs on different machines when more than one interfaces are in place. Hope this answers your question. – ArisKortex Nov 23 '16 at 20:37
  • so are you intending this to be used as part of automation? (I assume so due to the mention of parsing the output) if so does the process have to run locally on the machine or can it be run on a remote system querying the machine you want the MAC address of? – Mike Garuccio Nov 23 '16 at 21:20
  • Process - script in question - is going to ran locally on a machine. This is why I mention the deployment errors etc. But if you have any ideas please share them. – ArisKortex Nov 23 '16 at 21:48
  • If you can't parse the output of ipconfig, how can you parse the output of any other command? Any solution will give you several MACs if more than one interface exists, so you have to do the job. – Gregory MOUSSAT Nov 23 '16 at 21:55
  • Ipconfig tends to list details even for interfaces that are not enabled. In my case I have came across machines that have two interfaces with one of them being disabled. Doing an ipconfig on a machine like this will list details even for the disabled one. This creates additional overhead in a sense that it'll require more processing in order to extract the details of the correct. WMIC has the option to list only the enabled one. – ArisKortex Nov 25 '16 at 01:19
  • `Ipconfig tends to list details even for interfaces that are not enabled. In my case I have came across machines that have two interfaces with one of them being disabled. Doing an ipconfig on a machine like this will list details even for the disabled one.` - Without having the slightest clue why you're doing this, wouldn't knowing all MAC addresses be important, disabled interfaces as well? What if a disabled interface becomes enabled at some point? – joeqwerty Nov 26 '16 at 00:49

4 Answers4

1

You could use VBScript. The Code on http://www.robvanderwoude.com/vbstech_network_mac.php could be modified to get the information you need.

VBScript Code:

intCount = 0
strMAC   = ""
' We're interested in MAC addresses of physical adapters only
strQuery = "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID > ''"

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If InStr( strMAC, objItem.MACAddress ) = 0 Then
        strMAC   = strMAC & "," & objItem.MACAddress
        intCount = intCount + 1
    End If
Next

' Remove leading comma
If intCount > 0 Then strMAC = Mid( strMAC, 2 )

Select Case intCount
    Case 0
        WScript.Echo "No MAC Addresses were found"
    Case 1
        WScript.Echo "MAC Address: " & strMAC
    Case Else
        WScript.Echo "MAC Addresses: " & strMAC
End Select

Requirements: Windows version: Windows NT 4 SP4, 2000, XP, Server 2003, or Vista
Network: TCP/IP
Client software: WMI CORE 1.5 for Windows NT 4
Script Engine: any
Summarized: Works in Windows NT 4 SP4 (with WMI CORE 1.5), Windows 2000 or later. Doesn't work in Windows 95, 98 or ME.

bummi
  • 162
  • 2
  • 2
  • 9
  • Thanks very much for this. I did consider using VB to do this but I rejected it as an option. In any way, I proceeded with using WMIC. – ArisKortex Nov 29 '16 at 13:01
0

1.Open the CMD /a

2.Type nbstat -A followed by {machine IP}

3."Enter

4.Output = Machine NET-BIOS info, including MAC ID

You can alternatively use the -a switch and machine name (if known)

  • 1
    No, no, no. Don't do this. It relies on NetBIOS over TCP/IP which is a critical security risk. You should not recommend this to others. – Greg Askew Nov 26 '16 at 01:06
0

It may a bit out of the scope of what you can do but it's full proof and simple if you have the IPs of all the machines.

Go to a core switch/router, or any device that has an interface in the same subnet(s). If you dont have access to a the router/switch, you can do it from a windows box in the same subnet.

Ping all the IPs or do a ping sweep, then print the arp table. At that point all you have to do is copy and paste that into your favorite text manipulator (notepadd++, excel, linux, etc) and filter out lines you dont need.

No need to rely on pesky windows cmdlets that aren't always compatible or randomly fail and this method will work with for all devices not just windows.

person
  • 397
  • 1
  • 2
  • 10
0

Linux has a great utility called arp-scan which can scan your network and generate a table with MAC addresses and their corresponding IP addresses. Sadly, it doesn't come included with Knoppix. I don't know about other live distros.

Charles Burge
  • 768
  • 6
  • 16