Need a simple bat file to test ping on a list

March 21, 2011 at 11:01:25
Specs: Windows 7
I have a list of 300 machines I need to test and see if I can get a ping back from them. Does anybody have a simple bat file or script that I can dump these machine names into and have it outout to a txt file if it was able to ping or not?

See More: Need a simple bat file to test ping on a list

Report •

March 21, 2011 at 11:29:24
Not a simple one but...

@echo off

set OutputFile=result.txt
set ListFile=servers.txt
echo y|del %OutputFile%

for /f "tokens=1,2 delims= " %%a in (%ListFile%) do (
  call :Sub "%%a" "%%b"
  echo Checking "%%a" "%%b")
notepad "%OutputFile%"
goto :eof

  ping %1 -n 1 > NUL
    set state=Off Line
    set name=%1
    set IP=
  ) else (
    set Name=%2
    set state=On Line
    call :RDNS %1
  echo %Name%,%state%   %IP%,%2 >> "%OutputFile%"
goto :eof

 for /f "tokens=1,2 delims= " %%A in ('nslookup %1') do (
  if "%%A"=="Name:" call :SetName "%%B"
  if "%%A"=="Address:" call :SetIP "%%B"
  if "%%A"=="Addresses:" call :SetIP "%%B")
goto :eof

  set IP=%1
goto :eof
  set Name=%1
goto :eof

In servers.txt you can place IPs or FQDN along with descriptions... File Server SQL Server DC
DESKTOP-02094 JohnDoe
DESKTOP-02095 JaneDoe

and the results in the result.txt file would look like...

svr3.mydomain.local,On Line,File Server 
svr2.mydomain.local,On Line,SQL Server
svr1.mydomain.local,On Line,DC 
DESKTOP-02094,Off Line,JohnDoe
DESKTOP-02095,On Line,JaneDoe

You can play with this line to change the order or remove things you don't want...

echo %Name%,%state%   %IP%,%2 >> "%OutputFile%"

Report •

March 21, 2011 at 12:22:54
If you plan on doing this from a Win7 box, PowerShell makes this fairly trivial:
Get-Content serverList.txt | Where-Object {-not (Test-Connection $_ -Count 4 `
  -ErrorAction SilentlyContinue)} > noPing.txt

How To Ask Questions The Smart Way

Report •

March 21, 2011 at 13:09:23
These work!

Thank you.

Report •

Related Solutions

Ask Question