Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

telnet.ps1 - powershell script by ActiveXperts Software

telnet.ps1 establishes a telnet session to a host and validates its response.

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


telnet.ps1 script code

#################################################################################
# ActiveXperts Network Monitor PowerShell script, © ActiveXperts Software B.V.
# For more information about ActiveXperts Network Monitor, visit the ActiveXperts 
# Network Monitor web site at http://www.activexperts.com
#################################################################################
# Script
#     Telnet.ps1
# Description: 
#     Establish a telnet session to a POP3 mail server and validate its response
#     POP3 servers always reply a #+OK# 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
# Declare Parameters:
#     1) strHost (string) - a telnet server to connect to
#     2) numPort (int) - the port to connect to
#     3) strCommand1 (string) - the first command to send to the telnet server
#     4) strCommand2 (string) - the second command to send to the telnet server
#     5) strCommand3 (string) - the third command to send to the telnet server
#     6) strReceive (string) - the string you should receive
# Usage:
#     .\Telnet.ps1 '<Hostname | IP>' <Port> '<Command1>' '<Command2>' '<Command3>' '<Receive string>'
# Sample:
#     .\Telnet.ps1 'telnet.activexperts-labs.com' 23 'library' 'mypasswd' '' 'library'
#################################################################################

# -- Declare Parameters
param( [string]$strHost = '', [int]$numPort = 0, [string]$strCommand1 = '', [string]$strCommand2 = '', [string]$strCommand3 = '', [string]$strReceive = '' )  

# -- Use _activexperts.ps1 with common functions 
. 'C:\Program Files\ActiveXperts\Network Monitor\Scripts\Monitor (ps1)\_activexperts.ps1' 


#################################################################################
# // --- Main script ---
#################################################################################

# -- Clear screen and clear error
cls
$Error.Clear()

# -- Validate parameters, return on parameter mismatch
if( $strHost -eq '' -or $numPort -eq 0 -or $strCommand1 -eq $null -or $strCommand2 -eq $null -or $strCommand3 -eq $null -or $strReceive -eq '' )
{
  $res = 'UNCERTAIN: Invalid number of parameters - Usage: .\Telnet.ps1 "<Hostname | IP>" "<Port>" "<Command1>" "<Command2>" "<Command3>" "<Receive string>"'
  echo $res
  exit
}

# Declare local variables by assigning an initial value to it
$strExplanation = ''

# Assign return value to $dummy so the return value is hidden in the console
$dummy = AxCheckTelnet $strHost $numPort $strCommand1 $strCommand2 $strCommand3 $strReceive ([ref]$strExplanation)

echo $strExplanation
exit


#################################################################################
# // --- Catch script exceptions ---
#################################################################################

trap [Exception]
{
  $res = 'UNCERTAIN: ' + $_.Exception.Message
  echo $res
  exit
}