萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Windows XP 教學

WinXP 批次檔追蹤 DHCP IP 範圍使用情況:只記錄未使用 IP 到文字檔

需掃描某 IP 範圍(如 192.168.1.1~100)找出未被使用的 IP?直接在命令列跑 FOR /L 迴圈會刷滿畫面。改寫批次檔,只將「Request timed out」的 IP 記錄到 IPList.txt,並自動開啟記事本顯示結果。

IP 掃描示意

批次檔內容(存為 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 替換為你的實際網段。
  • 目標電腦開啟防火牆封鎖 ICMP 會誤判為離線。

適用範圍與現代替代

  • XP/2000/2003 通用;Win7/8/10/11 同樣可用(命令列/批次檔/PowerShell)。
  • 圖形化工具推薦:Advanced IP Scanner(免費、多執行緒、可匯出 CSV、掃描共享資料夾/遠端關機/喚醒)。
  • PowerShell 一行:1..100 | % { $ip="192.168.1.$_"; if(!(Test-Connection -Count 1 -Quiet $ip)) { "$ip Down" | Out-File -Append DownIPs.txt } }
copyright © 萬盛學電腦網 all rights reserved