在處理 Windows XP 的 DHCP 故障、網路規劃或安全稽核時,常需快速找出特定 IP 範圍內未被使用的位址。單純使用 ping 逐一測試不僅耗時,輸出資訊龐大難以分析。本文介紹透過批次檔自動化掃描,並僅記錄無回應的 IP 位址至文字檔,大幅提升效率。
利用 For /L 迴圈搭配 ping -n 2(發送 2 個封包),遍歷指定範圍。範例掃描 192.168.1.1 至 192.168.1.100:
For /L %f in (1,1,100) Do Ping.exe -n 2 192.168.1.%f
@Echo off
date /t > IPList.txt
time /t >> IPList.txt
echo =========== >> IPList.txt
For /L %%f in (1,1,100) Do Ping.exe -n 2 192.168.1.%%f | Find "Request timed out." && echo 192.168.1.%%f Timed Out >> IPList.txt && echo off
cls
Echo Finished!
@Echo on
Notepad.exe IPList.txt
For...In...Do 指令需寫在同一行,以 && 串接多個子指令Find "Request timed out." 過濾無回應的 IPIPList.txt 並以記事本開啟掌握此技巧,即可在 XP 區域網路環境快速盤點 IP 使用狀態,協助網路故障排除與 IP 規劃管理。