Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

ica.vbs - vbscript script by ActiveXperts Software

ica.vbs establish a telnet session to an MS ICA Server and validate its response.

Use ica.vbs directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select ica.vbs. Configure the required parameter, or press 'Load a working sample'.

In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.


ica.vbs script code

' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor  - VBScript based checks
' // For more information about ActiveXperts Network Monitor and VBScript, visit
' // http://www.activexperts.com/support/network-monitor/online/vbscript/
' ///////////////////////////////////////////////////////////////////////////////

Option Explicit

' Declaration of global variables
Dim   SYSDATA, SYSEXPLANATION   ' SYSDATA is displayed in the 'Data' column in the Manager; SYSEXPLANATION in the 'LastResponse' column

' Constants - return values
Const retvalUnknown = 1         ' ActiveXperts Network Monitor functions should always return True (-1, Success), False (0, Error) or retvalUnknown (1, Uncertain)


' // To test a function outside Network Monitor (e.g. using CSCRIPT from the
' // command line), remove the comment character (') in the following lines:
' Dim bResult
' bResult = CheckIca( "nntp.activexperts-labs.com" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
' ////////////////////////////////////////////////////////////////////////////////////////

Function CheckIca( strHost )
' Description: 
'     Establish a telnet session to an ICA server and validate its response
'     ICA servers always reply a 'ICA' message when ready to establish a session
'     This function uses ActiveXperts Network Component.
'     ActiveXperts Network Component is automatically licensed when ActiveXperts Network Monitor is purchased
'     For more information about ActiveXperts Network Component, see: www.activexperts.com/network-component
' Parameters:
'     1) strHost  - Host name or IP address of the mail server
' Usage:
'     CheckIca( "<Hostname | IP>" )
' Sample:
'     CheckIca( "nntp.activexperts-labs.com" )

  CheckIca        = retvalUnknown  ' Default return value, and will be shown as a yellow (uncertain) icon in the Manager
  SYSDATA         = ""             ' SYSDATA displayed in the 'Data' column in the Manager          
  SYSEXPLANATION  = ""             ' SYSEXPLANATION displayed in the 'LastResponse' column in the Manager

  CheckIca        = checkTelnet( strHost, 1494, "", "", "", "ICA" )

End Function



' //////////////////////////////////////////////////////////////////////////////
' // --- Private Functions section ---
' // Private functions names should start with a lower case character, so they 
' // will not be listed in the Network Monitor's function browser.
' //////////////////////////////////////////////////////////////////////////////

Function checkTelnet( strServer, numPort, strCommand1, strCommand2, strCommand3, strReceive )

  Dim objTcp, strAllResponses

  checkTelnet           = 1   ' Default return value
  SYSDATA               = ""  ' Not used by this function
  SYSEXPLANATION        = ""  ' Set initial value

  Set objTcp = CreateObject("AxNetwork.Tcp")
  objTcp.Protocol       = 2 ' 1 means: raw, 2 means: telnet (see also ActiveXperts Network Component manual)

  objTcp.Connect strServer, numPort
  If( objTcp.LastError <> 0 Or objTcp.ConnectionState <> 3 ) Then
    checkTelnet       = False
    SYSEXPLANATION    = "Unable to connect to [" & strServer & "]"
    objTcp.Disconnect ' can be called even when there's no connection
    Exit Function
  End If

  objTcp.Sleep( 2000 ) ' Allow some time

  tcprecv objTcp, strAllResponses 

  tcpsend objTcp, strCommand1
  tcprecv objTcp, strAllResponses

  tcpsend objTcp, strCommand2
  tcprecv objTcp, strAllResponses

  tcpsend objTcp, strCommand3
  tcprecv objTcp, strAllResponses

  If( InStr( UCase( strAllResponses ), UCase( strReceive )  ) <> 0 ) Then
    checkTelnet         = True
  Else
    checkTelnet       = False
  End If
  SYSEXPLANATION      = "Response=[" & strAllResponses & "]"

  objTcp.Disconnect    

End Function

Sub tcpsend( objTcp, strCommand )
  If( strCommand <> "" ) Then
    objTcp.SendString( strCommand )
  End If
End Sub

' //////////////////////////////////////////////////////////////////////////////

Sub tcprecv( objTcp, BYREF strAllResponses )
  Dim bHasData, strResponse 

  bHasData = objTcp.HasData

  While( bHasData )
    strResponse = objTcp.ReceiveString()
    bHasData = objTcp.HasData

    If( strAllResponses <> "" ) Then
      strAllResponses = strAllResponses & ".." ' .. to indicate a newline
    End If
    strAllResponses = strAllResponses & strResponse
  WEnd
End Sub