If you’re managing a small local network and want a quick way to check which IP addresses are active (online), you can easily automate this task using a batch file script. This method is ideal for network administrators, IT students, or anyone curious about who’s connected to their local network.

In this tutorial, we’ll show you how to ping a range of IP addresses (like 192.168.1.1 to 192.168.1.254) and log only the alive or responsive IPs into a text file named Active_ip.txt.


Why Use a Batch File to Ping IPs?

Using a batch file gives you:

  • ✔️ Automation: No need to ping each address manually.
  • ✔️ Efficiency: Scan your entire subnet in seconds.
  • ✔️ Logs: Automatically store results for analysis.
  • ✔️ Offline Use: No internet or extra software required.

🛠️ Batch Script to Find Active IP Addresses

Here is the script you need:

@echo off
setlocal enabledelayedexpansion

REM Set the base IP (adjust if your network is different)
set baseIP=192.168.1

REM Output file
set outputFile=Active_ip.txt
echo Scanning active IPs on the network... > %outputFile%

REM Loop through IP range 1 to 254
for /L %%i in (1,1,254) do (
    set ip=%baseIP%.%%i
    ping -n 1 -w 200 !ip! | find "TTL=" >nul
    if !errorlevel! == 0 (
        echo !ip! is alive
        echo !ip! >> %outputFile%
    )
)

echo.
echo Scan complete. Active IPs saved in %outputFile%
pause

📝 Steps to Use the Script

  1. Open Notepad on your Windows system.
  2. Copy and paste the above script.
  3. Save the file with a .bat extension, for example: PingScan.bat
  4. Double-click the file to run it, or right-click and choose “Run as Administrator” for better access.
  5. After the scan finishes, check the Active_ip.txt file in the same folder. It will contain a list of all responsive IPs.

📌 Customizations You Can Make

  • Change 192.168.1 to match your own local IP subnet.
  • Modify the IP range by changing the loop range (1,1,254).
  • Add timestamp logging or output in CSV format if needed.

🔚 Conclusion

Using a batch file to ping all IPs in your local network is a smart and fast way to discover active devices without installing any additional tools. It’s especially useful for small office, lab, or home networks. With just a simple script and a few seconds, you’ll know exactly who’s online!

Leave a Reply

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