在區域網路需快速掃描某網段哪些 IP 可用、哪些無回應,可撰寫批次檔利用 FOR /L 迴圈配合 PING 與 FIND 過濾「Request timed out」,自動產出文字報表。
PingIP.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.0.%%f | Find "Request timed out." && echo 192.168.0.%%f Timed Out >> IPList.txt
cls
Echo Finished!
@Echo on
Notepad.exe IPList.txt
For /L %%f in (1,1,100):變數 %%f 從 1 遞增至 100。Ping.exe -n 2:每個 IP 送 2 個封包(預設 4 個太慢)。Find "Request timed out.":僅擷取無回應的 IP。&&:前一指令成功(找到字串)才執行後續 echo 記錄。IPList.txt 含日期、時間與所有逾時 IP 清單。192.168.0 修改為你實際網段(如 192.168.1、10.0.0)。(1,1,254)。1..254 | % { $ip="192.168.1.$_"; if(!(Test-Connection -Count 1 -Quiet $ip)) { $ip + " Down" | Out-File -Append DownIPs.txt } }