需掃描某 IP 範圍(如 192.168.1.1~100)找出未被使用的 IP?直接在命令列跑 FOR /L 迴圈會刷滿畫面。改寫批次檔,只將「Request timed out」的 IP 記錄到 IPList.txt,並自動開啟記事本顯示結果。
IPTracker.bat)@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
cls
Echo Finished!
@Echo on
Notepad.exe IPList.txt
FOR...DO 指令必須在 同一行,以 && 串接。%%f 在批次檔中雙百分號,命令列單獨執行用單百分號 %f。192.168.1 替換為你的實際網段。1..100 | % { $ip="192.168.1.$_"; if(!(Test-Connection -Count 1 -Quiet $ip)) { "$ip Down" | Out-File -Append DownIPs.txt } }