Let´s say I have here a text file with some computer names (each line == 1 name):
computerA
computerB
computerC
...Is it possible to create a batch file that is pinging all of these computers? And actually a ping is a big output. I don't need the time or other information; I just would like to know reachable or not. Any ideas?
It´s working now! The problem was like fox said, that I named my batch file as ping.bat and ping is also a command so this did not work out. I renamed my batch file and now everything is fine.
6 Answers
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)
pauseIf 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&ExitOutput:
[+] Pinging: [OK]
[+] Pinging: ffff [FAILED] 7 Suggest using powershell, this is faster compared to the traditional ping, here is the cmd,
If you want more details, refer here
$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 } } An alternative you may wish to look at is to use PowerShell:
cls;
ForEach ($targetComputer in (Get-Content C:\installs\computerlist.txt)) { if (Test-Connection -ComputerName $targetComputer -Count 1 -Quiet) { "$targetComputer - Ping OK" } else { "$targetComputer - Ping FAIL" }
}Replace the contants of C:\Installs\ComputerList.txt and you're away :)
I created a ping tool that uses a config file for setting which ip's to ping and creates up to 12 cmd windows and places them side-by-side on your screen. Each window has a description in the title, also from the config file.
It autodetects your screen size, but currently only supports 1920x1080 and 1600x900. You can create more resolutions manually though. See credits.txt for info.
You can try to use the tool I developed - ccmd - to help with similar tasks, it runs any terminal command against a number of targets, targets can be given in csv text file like:
#this is a comment line
#target, description, command (default - ping)
8.8.8.8
1.1.1.1
#in below command {target} will be replaced with 8.8.4.4
8.8.4.4, google DNS, ping -n 1 -w 500 {target}
192.168.1.0/30, my subnet
bbc.com, this is bbc news site
save above file in name.txt and point the script to it with -s option, by default it will run ping command if no other command given.
Run it with:
ccmd.exe -s name.txt -b 10 -c 30
reveals that output:
script written on python but has ccmd.exe vesion, that can be run on windows directly. By default details command logs output saved in ./LOG/ folder.
Source: