Ping Range of IPs in Batch

I recently had a need to scan the local network for running hosts. Since I really didn’t want to download any network scanning applications and I also didn’t want to install winpcap so I could use nmap, I decided to write my own handy batch script to do the scanning.

 

It will automatically detect your IP address and scan the network that you’re on. If you’re connected to multiple networks, it will scan them all. If you have multiple network adapters connected to the same network, you’ll end up scanning that network multiple times.

 

Use this version for XP:

@echo off
for /f "usebackq tokens=1-2 delims=:" %%i in (`ipconfig ^| find "IP Address"`) do (
    for /f "tokens=1-3 delims=." %%k in ("%%j") do (
        echo Sweeping network from%%k.%%l.%%m.1 to%%k.%%l.%%m.254...
        for /l %%c in (1,1,254) do ping -n 1 %%k.%%l.%%m.%%c | find /i "reply"
    )
)

And this version for Vista and Windows 7:

@echo off

for /f "usebackq tokens=1-2 delims=:" %%i in (`ipconfig ^| find "IPv4 Address"`) do (
for /f "tokens=1-3 delims=." %%k in ("%%j") do (
echo Sweeping network from%%k.%%l.%%m.1 to%%k.%%l.%%m.254...
for /l %%c in (1,1,254) do ping -n 1 %%k.%%l.%%m.%%c | find /i "reply"
)
)



Back to Article Index

blog comments powered by Disqus