網管需快速掃描 DHCP 範圍內哪些 IP 未被使用。單純 ping 迴圈會輸出大量資訊,難以閱讀。撰寫批次檔僅記錄「請求逾時」的 IP 並存成文字檔,即可快速盤點可用 IP。
@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." >nul
If ErrorLevel 1 Echo 192.168.1.%%f Timed Out >> IPList.txt
)
cls
Echo Finished!
Notepad.exe IPList.txt
IPTracker.bat。192.168.1 為目標網段,(1,1,100) 為掃描範圍(起始、遞增、結束)。IPList.txt 顯示未使用 IP 清單。For /L %%f in (start,step,end) 產生迴圈變數。Ping -n 2 僅送 2 個封包加速掃描。Find "Request timed out." 偵測無回應,ErrorLevel 1 表示找到(即逾時)。Find 指令)。此批次檔適合快速臨時盤點,一寫永用,大幅減少人工比對負擔。