I wrote a very simple “for” loop a week or two ago to ping everything on a network and populate the arp table so I could get a list of mac addresses. I found it today and wanted to improve it a bit, I found a script by DavidPostell ,on Superuser.com, and used his batch script to improve mine dramatically. Basically, with the code he wrote, I was able to quickly parse out the first 3 octets of my computers IP address, and use that instead of needing to edit the batch file for every network. Feel free to use this for whatever, it was just a fun short exercise me and I thought it might be useful if you wanted to get mac addresses. It saves some of the output to a file, but deletes the file after presenting it to you, but you can add a “rem” to the line that starts out “del pscan…”, or remove the line. Why did I spend time on this is a question for another day. While this was nearly a complete waste of time, I think a neat addition to this could be to print out all the numbers, then redraw the entire screen after each success or fail, and colorize the numbers, additionally redrawing with the ip-arp mappings as well as response time across the bottom, which would give it a really ncurses-ey type feel, but also be an enormous amount of resources for something whose goal is to simply fill an arp table. Better would be to write it out to a json file and upload it to a server so I can use it in another project I’m working on.
pscan.bat
@echo off
setlocal
setlocal enabledelayedexpansion
for /f "usebackq tokens=*" %%a in (`ipconfig ^| findstr /i "ipv4"`) do (
for /f delims^=^:^ tokens^=2 %%b in ('echo %%a') do (
for /f "tokens=1-4 delims=." %%c in ("%%b") do (
set _o1=%%c
set _o2=%%d
set _o3=%%e
set _o4=%%f
set _3octet=!_o1:~1!.!_o2!.!_o3!.
echo [31mscanning !_3octet!1-254 [0m
for /l %%x in (1,1,254) do (
ping -n 1 %%c.%%d.%%e.%%x |findstr Reply |findstr bytes >>pscan.bat.output.txt
echo|set /p =...%%x
)
echo.
echo:
arp -a >>pscan.bat.output.txt
more pscan.bat.output.txt >nul 2>&1
del pscan.bat.output.txt >nul 2>&1
)
)
)
endlocal
Here is a download for the batch file, it is renamed as .txt, so you will need to change that, but it should work if the formatting above is messed up.