Saturday, September 5, 2020

Finding devices on the LAN from the DOS prompt

Every once in a while, I want a simple but elegant way to do things. No downloads, no complications.

Tonight, I was looking for an easy way to see what devices were attached to my local network without using a hefty network tool. It took me a little longer than I'd hoped, but I managed to whip up a little batch file (yep, old school!) to help me find a device that was trying to hide from me.

I call it: findping

Here's the batch file. It takes two parameters, which are the starting and ending numbers of the last octet:

@echo off
set subnet=192.168.0
echo Searching IP Range: %subnet%.%1 - %subnet%.%2
for /l %%i in (%1,1,%2) do (
    @ping -n 1 %subnet%.%%i | find /i "Reply from %subnet%.%%i:"
    if not ERRORLEVEL 1 (
        rem valid response
    ) else (
        echo Polling IP %subnet%.%%i: no response
    )
)
set subnet=
echo Done.
So the usage looks something like this:

findping 100 254

Then it scans through each of the IPs in the range of 192.168.0.100 though 192.168.0.254.

If you want to change the class C subnet you're searching, simply change that in the second line of the batch file (the "set subnet" line).

If you need to store the results to a file on disk, perhaps to run through a spreadsheet later, you can pipe the output that way as well:

findping 1 100 > search.txt

I hope you folks find this as useful as I did!