Posted in Uncategorized

VBscript: Pinger or Ping servers and alert Sys Admins

I needed simple monitoring tool to ping and send emails when hosts are down. I found few free tools, but I need to build my script so I can use variety of purposes.  Here you go,

‘* Script Name: Pinger.vbs
‘* Arguments: ServerName
‘* This script tries to ping the specified server. If the server is NOT pingable
‘* it will send send email to administrators
‘* Written by: Anand Venkatachalapathy
Dim ServerName
Public MailFrom, MailTo
Public sSMTpServerName

‘* Assign a SMTP server
sSMTPServerName = ""

‘Enter the correct values for who to alert and from address.
MailFrom = ""
‘Enter more addresses with delimited by semicolon below
MailTo = ""

ServerName = WScript.Arguments(0)
If IsAlive(ServerName) Then
      WScript.Echo ":-)"
      Notify_Admins ServerName
End If

‘* End of Script

‘* Function: IsAlive
‘* Purpose: Ping the Server and return True if pingable, return False if not
‘* not pingable
Function IsAlive(ServerName)
      Set WshShell = CreateObject("WScript.Shell")
      PINGFlag = Not CBool("ping -n 1 " & ServerName,0,True))
      If PINGFlag = True Then
              ‘Successful ping
              IsAlive = True     
              ‘Unsuccessful ping
              IsAlive = False
      End If
End Function

‘* Sub-routine: Notify_Admins
‘* Purpose: Send email to system administrators
Sub Notify_Admins (ServerName)
        ‘* iMsg – holds CDO.Message object
        ‘* Flds – Enumeration for CDO SMTP object properties
        ‘* iConf – holds CDO.Configuration
        Dim iMsg, Flds, iConf
        ‘* SBody – Email Body message
        Dim SBody
        ‘* Assign cdoSendUsingPort is set to 2, i.e., send using SMTP (25) port
        Const cdoSendUsingPort = 2
        ‘* Create CDO Objects and assign to variables
        Set iMsg = CreateObject("CDO.Message")
        Set iConf = CreateObject("CDO.Configuration")
        Set Flds = iConf.Fields
        ‘* Assign values to Flds class properties
        With Flds
            .Item("") = cdoSendUsingPort
            .Item("") = sSMTPServerName
            .Item("") = 25 
        End With
        ‘* Setting up the Body of the Email message
        sBody = ServerName & " is not pingable on " & Now
        ‘* Assign message properties and Send the mail
        With iMsg
           Set .Configuration = iConf
           .Fields("urn:schemas:httpmail:importance").Value = 2    ‘Setting Mail importance to High (2)
           .To = MailTo
           .From = MailFrom           ‘Fake, but make-sense email FROM address
           .Sender = MailFrom               ‘Return Email address
           .Subject = ServerName & ": Not Pingable"
           .TextBody = sBody
        End With
End Sub


Being in Silicon Valley for years, I became a IT Infrastructure Geek by experience and surrounded by other Geeks everywhere. I try to help others by the solutions I found on odd occasions.

One thought on “VBscript: Pinger or Ping servers and alert Sys Admins

Leave a Reply to Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s