I am on a Windows platform (Win7) and I have a scenario where I know the MAC addresses of devices but their IPs are dynamically chosen when booting up.
I want to write a batch script that pings these specific devices to make sure they are alive. There are many other devices on the network that I don't want to ping, just a set of 10 specific MACs I want to get the IP address from then ping them only. They are all in the address scheme 10.1.(1-255).(1-255)
This much I know, I can ping the entire address spectrum and then
arp -a > arp.txt
...to output a document containing the list of IPs and associated MAC addresses in this format
Interface: 192.168.2.27 --- 0xb
Internet Address Physical Address Type
192.168.2.1 00-1f-90-c0-25-fd dynamic
192.168.2.3 00-00-aa-a1-d3-78 dynamic
192.168.2.16 ac-72-89-a7-7e-98 dynamic
192.168.2.17 78-45-c4-2f-71-0b dynamic
192.168.2.18 68-b5-99-8e-1c-35 dynamic
192.168.2.24 b8-ac-6f-30-00-34 dynamic
192.168.2.26 00-90-a9-6f-e0-be dynamic
My question is how can I (via a batch script or other automated method) find the line of the MAC address I am interested in and put the IP address into a variable that I can then use.
In UNIX I can grep but in Windows I'm at a loss.
Thanks in advance for any help.
Pipe the output to find
and use a for
loop.
for /f "tokens=1,2,3 delims= " %%i in ('arp -a ^| find "00-1f-90-c0-25-fd"') do (
set ip=%%i
set mac=%%j
)
You could alter this a bit to make a batch script that will ping by entering the MAC address like so pingbymac.bat 00-1f-90-c0-25-fd
@for /f "tokens=1,2,3 delims= " %%i in ('arp -a ^| find "%~1"') do (
ping %%i
)