Arp populating scan script

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, 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.



@echo off
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 scanning !_3octet!1-254 
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
arp -a >>pscan.bat.output.txt
more pscan.bat.output.txt >nul 2>&1
del pscan.bat.output.txt >nul 2>&1

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.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.