I got a call last week from a member of one the other teams where I work. He asked, “Do you have a script which will resolve a list of IP Addresses to MAC Addresses?” My answer was, “not yet”. I did a search and found some very convoluted Pinvoke code. I wanted something easier.
When I automate a task, I begin with the manual steps for the task. To get a MAC address from an IP address, I ping the address, then look at the ARP cache. Get-MACFromIP.ps1 does the same thing, using the inline script method to make the process run in parallel for speed. It does not require any administrative rights to run, and is an advanced function. A use example follows, others are in the code help:
#Get List from IPList.txt on the desktop
$logfile = "$env:userprofile\Desktop\IP_MACs.csv"
Get-MACfromIP -IPList $IPAddress |
Export-Csv -NoTypeInformation -Path $logfile -force
I the use WMI ping method to enable name resolution and the return codes. The script outputs the IP address, DNS Name (if it can be resolved), MAC address, and the verbose level ping reply. Capture of the output of the ARP table is based on this post, by Joe Keohan. Version 1.1 added support for alternate MAC format of ‘0000.1111.2222’.Script Text