Ping every IP address in a text file?
Try this:
@echo off
for /f "delims=" %%a in (computerlist.txt) do ping -n 1 %%a >nul && (echo %%a ok) || (echo %%a failed to respond)
pause
If you have to use a filename or path with spaces or odd characters then Instead of (computerlist.txt)
use ( ' type "c:\folder\computer file.txt" ' )
@Echo OFF
For /F "Usebackq Delims=" %%# in (
"List.txt"
) do (
Echo+
Echo [+] Pinging: %%#
Ping -n 1 "%%#" 1>nul && (
Echo [OK]) || (
Echo [FAILED])
)
Pause&Exit
Output:
[+] Pinging: www.google.com
[OK]
[+] Pinging: ffff
[FAILED]
Suggest using powershell, this is faster compared to the traditional ping, here is the cmd,
If you want more details, refer here https://tech3motion.com/powershell-cmd-to-ping-list-of-servers-ip/
$InputFile = 'C:\Temp\MachineList.txt'
$machines = Get-content $InputFile
foreach ($machine in $machines){
if (Test-Connection -ComputerName $machine -Count 1 -ErrorAction SilentlyContinue){
Write-Host "$machine,up" -ForegroundColor Green
}
else{
Write-Host "$machine,down" -ForegroundColor Red
}
}