Ping multiple computers

I came across this need  to check the availability of multiple devises by pinging them  , this script will preform ping to computers from a csv file and will create another CSV file with the computer name and true if it has ping false if it doesn’t

There are two script

1. Ping to Computer name

2. Ping to IP address

You will need to create a CSV file with the computer list and call it – “Complist.csv”

save it in the same folder with the script

the script will run on this file and create a new file called  “complist-ping.csv”

Search by Computer name  Script :

  • Copy the text and save it as VBS

Function Ping(strHost)
  Ping = False
  set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = ‘" & strHost & "’")
  for each objRetStatus in objPing
    if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
      Ping = False
    else
      Ping = True
    end if
  next
  set objPing = nothing
End Function
 
set fs = CreateObject("Scripting.FileSystemObject")
set objfile = fs.OpenTextFile("complist.csv")
i = 0
Set mf = fs.CreateTextFile("complist-ping.csv",false)
do while not objfile.AtEndOfStream
  arr2 = split(objfile.ReadLine,",")
  if (ubound(arr2) <> -1) then
    if (left(arr2(0),1) <> ";")and(left(arr2(0),1) <> "#") then
      mf.writeline(arr2(0) & "," & cstr(Ping(arr2(0))))
      i = i + 1
    end if
  end if
Loop
objfile.close
mf.close
set objfile = nothing
 
set fs = nothing
set wa = nothing
set objEnv = nothing
set objNetwork = nothing
wscript.echo "Done " & i

Search by IP Address

  • Copy the text and save it as VBS

Function Ping(strIP)
  Ping = False
  set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = ‘" & strIP & "’")

  for each objRetStatus in objPing
    if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
      Ping = False
    else
      Ping = True
    end if
  next
  set objPing = nothing
End Function
 
set fs = CreateObject("Scripting.FileSystemObject")
set objfile = fs.OpenTextFile("complist.csv")
i = 0
Set mf = fs.CreateTextFile("complist-ping.csv",false)
do while not objfile.AtEndOfStream
  arr2 = split(objfile.ReadLine,",")
  if (ubound(arr2) <> -1) then
    if (left(arr2(0),1) <> ";")and(left(arr2(0),1) <> "#") then
      mf.writeline(arr2(0) & "," & cstr(Ping(arr2(0))))
      i = i + 1
    end if
  end if
Loop
objfile.close
mf.close
set objfile = nothing
 
set fs = nothing
set wa = nothing
set objEnv = nothing
set objNetwork = nothing
wscript.echo "Done " & i

Good luck Smile

This entry was posted in Scripts, Windows. Bookmark the permalink.

Leave a Reply