TechColumnist Storage Information Blog

9Aug/070

Ping a list of machines from txt

This vbscript pings machines from a text file:

change the two variables for your input and output txt files:
strPATHout = "C:\pingstatus.txt"
strPATHin = "C:\pinglist.txt"

ON ERROR Resume Next

'Define log paths (disable in portions if not using a reference file)
strPATHout = "C:\#active\pingstatus.txt"
strPATHin = "C:\#active\pinglist.txt"

'Define additional variables here
sMsgboxtxt = "ping?" 'message box text here
sMsgboxttl = "ping?" 'message box title here
sLogTitle = "ping?" 'log file title string

'Standard message stating whether you want to do this or not
intReturn = Msgbox(sMsgboxtxt, vbYesNo, sMsgboxttl)
If intReturn = vbNo Then
Wscript.echo "Quitting"
WScript.quit
End If

'Create filesystem objects (comment out OBJin if not using reference file)
Set OBJfs = CreateObject("Scripting.FileSystemObject")
Set OBJin = OBJfs.OpenTextFile(strPATHin)
Set OBJout = OBJfs.CreateTextFile(strPATHout,True)

OBJout.WriteLine(sLogTitle & " - " & Now)

Do Until OBJin.AtEndOfStream
strComputer = lcase(OBJin.Readline)

pingstatus = Ping(strComputer)
OBJout.WriteLine(strComputer & "," & pingstatus)
wscript.echo strComputer & "," & pingstatus

Loop

function Ping(sComputer)
dim objShell, objPing, strPingOut, flag
set objShell = CreateObject("Wscript.Shell")
set objPing = objShell.Exec("ping -n 3 -w 1000 "& sComputer)
strPingOut = objPing.StdOut.ReadAll
if instr(LCase(strPingOut), "reply") then
flag = TRUE
if instr(LCase(strPingOut), "destination host unreachable") then
flag = FALSE
end if
else
flag = FALSE
end if
Ping = flag
end function
'close the file
OBJout.Close()
OBJin.Close()
Wscript.echo "Quitting"

' Quit the Script ----------------------------------------------------
WScript.quit

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Technorati
  • Twitter

About Tom Lasswell

about myself.
Tagged as: Leave a comment

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.