Sign in to follow this  
Followers 0
tlancaster

VBScript - Ping multiple ip addresses and machine names

17 posts in this topic

I got the same error initially however I noticed that if you name the vbs script something else other than "ping.vbs" then it will run without errors i.e. if you call it "ping1.vbs" your problem should be solved. Hope this helps :)

0

Share this post


Link to post
Share on other sites

Can you help me understand this script a little bit more? mainly the part below.

I understand online and offline but what does the last one mean Unknown host (no DNS entry?

If InStr(temp, "Reply from") Then

ofile.writeline item & ","&strip&","&"Online."

ElseIf InStr(temp, "Request timed out.") Then

ofile.writeline item &","&strip&","&"No response (Offline)."

ELSEIf InStr(temp, "try again") Then

ofile.writeline item & ","&strip&","&"Unknown host (no DNS entry)."

It's funny you'd ask for this, as I posted it today in another thread :) This does exactly what you asked, but I don't think it provides the results you asked for specifically. Also, it creates a .csv file, but that can easily be opened in excel for easy viewing. You can obviously edit it for your needs.

Anyway, here you go:

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
If not objFSO.FileExists("servers.txt") THEN
wscript.echo "Please create a file named 'servers.txt' with one PC name to be pinged per line,"&_
vbcrlf&"with a hard return at the end of each line."
wscript.quit
end if
tempobj="temp.txt"

Set objTextFile = objFSO.OpenTextFile("servers.txt", ForReading)
logfile="results.csv"
Set ofile=objFSO.CreateTextFile(logfile,True)
strText = objTextFile.ReadAll
objTextFile.Close
wscript.echo "Ping batch starting, please be patient. This could take some time to"&_
vbcrlf&"finish, depending on the number of hosts to check. You "_
&"will be "&vbcrlf&"notified upon the completion of this script."
ofile.WriteLine ","&"Ping Report -- Date: " & Now() & vbCrLf
arrComputers = Split(strText, vbCrLF)
for each item in arrcomputers
objShell.Run "cmd /c ping -n 1 -w 1000 " & item & " >temp.txt", 0, True
Set tempfile = objFSO.OpenTextFile(tempobj,ForReading)
Do Until tempfile.AtEndOfStream
temp=tempfile.readall
striploc = InStr(temp,"[")
If striploc=0 Then
strip=""
Else
strip=Mid(temp,striploc,16)
strip=Replace(strip,"[","")
strip=Replace(strip,"]","")
strip=Replace(strip,"w"," ")
strip=Replace(strip," ","")
End If

If InStr(temp, "Reply from") Then
ofile.writeline item & ","&strip&","&"Online."
ElseIf InStr(temp, "Request timed out.") Then
ofile.writeline item &","&strip&","&"No response (Offline)."
ELSEIf InStr(temp, "try again") Then
ofile.writeline item & ","&strip&","&"Unknown host (no DNS entry)."

End If
Loop
Next
tempfile.close
objfso.deletefile(tempobj)
ofile.writeline
ofile.writeline ","&"Ping batch complete "&now()
wscript.echo "Ping batch completed. The results will now be displayed."
objShell.Run("""C:\Program Files\Microsoft Office\OFFICE11\excel.exe """&logfile)

Create a file named servers.txt in the same folder as this script, with one computername/ip address that you'd like to ping per line. That should be all you need :)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.