9

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.

12

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" ' )

| improve this answer | |
  • I see the cmd is popping up very shortly and then it´s gone. Even with pause or sleep at the end I dont see any output. – sabisabi Apr 29 '13 at 11:36
  • Try the edited code above which includes the OK response. – foxidrive Apr 29 '13 at 12:39
  • No change at all, this is weird. I copy exact the same code (ok I change the filename) as you posted there into a textfile -> I save this as a .bat and after that I start the .bat file -> cmd popping up and then it´s gone without any output. I´m using win xp, could this be a problem? – sabisabi Apr 29 '13 at 13:36
  • Your path\filename probably contains spaces. Instead of (computerlist.txt) use ('type "c:\folder\computer file.txt" ') – foxidrive Apr 29 '13 at 13:46
  • 3
    That is your mistake. Always remember that when naming a batch file you should avoid using the name of a command. In your case the ping command inside the batch file is executing the ping batch file and not the ping command. – foxidrive Apr 30 '13 at 9:12
4
@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]
| improve this answer | |
  • When I start my .bat I see the output [+] Pinging: computerA , but then the window is disappearing. – sabisabi Apr 29 '13 at 11:38
  • You'he vopied my script as is without several changes? – ElektroStudios Apr 29 '13 at 12:43
  • Well I changed the name of the file, but that´s it – sabisabi Apr 29 '13 at 13:34
  • @sabisabi: start the batch file "manually" from an existing command prompt you you'll be able to read the error message. Don't "double click" batch files that you have to test. – a_horse_with_no_name Apr 29 '13 at 14:10
  • @a_horse_with_no_name if I start the .bat file via cmd (ping.bat) -> there is no new window and my cmd is closing itself without any message – sabisabi Apr 29 '13 at 14:15
1

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 :)

enter image description here

| improve this answer | |
0

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.

HellFires Pingtest v1.0

| improve this answer | |
0

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: https://i.stack.imgur.com/23zxQ.png

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: https://github.com/apraksim/ccmd

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.