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!

Constantly ping a PC and email if it drops offline

Status
Not open for further replies.

StevieM

IS-IT--Management
Jun 26, 2001
109
GB
I am looking for a script to do the above. I have a couple of remote machines that I need to know immediatly if they go offline.

Can anyone help?
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
To be honest I have nothing. My scripting experience is VERY limited. I have tried downloading a couple of scripts but nothing has done what I needed it to do.
 
The link below should help with the ping command:


The link below should help with the email:


Integrate them together and you should end up with a script that you want

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Thanks, that was a big help. I think I am almost there but having issues combining the 2.

For the ping part, if I run the script below I get the appropriate response...

START
Option Explicit

Dim strHost

' Check that all arguments required have been passed.
If Wscript.Arguments.Count < 1 Then
Wscript.Echo "Arguments <Host> required. For example:" & vbCrLf _
& "cscript vbping.vbs savdaldc01"
Wscript.Quit(0)
End If

strHost = Wscript.Arguments(0)

if Ping(strHost) = True then
Wscript.Echo "Host " & strHost & " contacted"
Else
Wscript.Echo "Host " & strHost & " could not be contacted"
end if

Function Ping(strHost)

dim objPing, objRetStatus

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
'WScript.Echo "Status code is " & objRetStatus.StatusCode
else
Ping = True
'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
end if
next
End Function
FINISH

And I can also use this email script and get an email out...

START
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "my email address"
objEmail.To = "my email address"
objEmail.Subject = "Server down"
objEmail.Textbody = "Server1 is no longer accessible over the network."
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = _
"my SMTP server"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
FINISH

To try and combine the 2 I want to replace the ELSE command with the email script but I get an error saying the objEmail is not defined
 
error saying the objEmail is not defined
Use the Dim instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top