Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

nntp.vbs - vbscript script by ActiveXperts Software

nntp.vbs establish telnet session to an NNTP news server and validate its response.

Use nntp.vbs directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select nntp.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.


nntp.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 = CheckNntp( "nntp.activexperts-labs.com" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"


Function CheckNntp( strHost )
' Description: 
'     Establish a telnet session to an NNTP news server and validate its response
'     NNTP servers always reply a '200' 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 news server
' Usage:
'     CheckNntp( "<Hostname | IP>" )
' Sample:
'     CheckNntp( "nntp.activexperts-labs.com" )

  CheckNntp       = retvalUnknown  ' Default return value
  SYSDATA         = ""             ' Not used by this function
  SYSEXPLANATION  = ""             ' Set initial value

  CheckNntp       = checkTelnet( strHost, 119, "", "", "", "200" )

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       = False
  Else
    checkTelnet       = True
  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