Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ping script

Status
Not open for further replies.

aikman

IS-IT--Management
Mar 10, 2003
4
SE
Hi,

I have a ping script that ping a computer and if it dont answer it will create a log file. I want help to change script to ping more than one server and create log file for every server.

Here is my script:

Option Explicit


Const cfgHost = "172.22.89.2"
Const cfgLogFile = "C:\test\Ping.log"

Dim PingStatus

Do While err.number = 0
PingStatus = Ping(cfgHost)
If PingStatus = False then
Dim objFS, objFile
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.OpenTextFile(cfgLogFile, 8 , true)
objFile.WriteLine date() & " " & time() & " - Svar kunde inte erhållas mot " & cfgHost
objFile.Close
Set objFS = Nothing
End If
WScript.Sleep(2500)
Loop


Function Ping(strHost)

Dim objPing, objRetStatus

set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & cfgHost & "'")

for Each objRetStatus in objPing
If IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
Else
Ping = True
End if
Next
End Function


thanks

Håkan
 
You are welcome to use the ping status function from my FAQ: faq329-4871

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top