During website construction, we can use Telnet Tool ActiveX for some programming. We have introduced the features of the Telnet Tool ActiveX control in the previous article. The following is an example of the application.
Programming example
The following is an ASP programming example of a simple Telnet Tool ActiveX control. The experiment environment is Windows 2000 Professional, IIS 5.0, SCO OpenServer 5.0.2, and Telnet Tool ActiveX control. Telnet Tool ActiveX control can download the 30-day trial version at www.dart.com, which only needs to be installed on the WEB server.
The program is not complex. After logging on to a sco unix system, two commands are executed and the command result is displayed on the browser page.
- HTML
- HEADTITLEPowerTCP Telnet Tool Demo Page/TITLE/HEAD
- BODY
- *******************************************************************
- Program: PowerTCP Telnet Tool Demo
- Author: Yin
- Date: 07/16/2001
- Purpose: To demonstrate how to login into a SCO UNIX server.
- ********************************************************************}
- Sub DoLogin()
- Session(RESULT) =
- On Error Resume Next
- Create a Telnet control
- Dim Telnet1
- Set Telnet1 = Server.CreateObject(Dart.Telnet.1)
- Use a 10 second timeout
- Telnet1.Timeout = 10000
- Specifies terminal type
- Telnet1.TermType = ansi
- AddResult Connecting to + txtHost + ... + vbCrLf
- Connect to the host on port 23
- Telnet1.Connect txtHost,23
- Dim a string to be used by the search method
- Dim Data
- Data =
- Search for login prompt
- Telnet1.Search Data, txtLoginPrompt
- AddResult Data
- Send username
- Telnet1.Send txtUser + vbCrLf
- Search for password prompt
- Telnet1.Search Data, txtPassPrompt
- AddResult Data
- Send password
- Telnet1.Send txtPass + vbCrLf + vbCrLf
- Search for command prompt
- Telnet1.Search Data, txtCommandPrompt
- AddResult Data
- Send command
- Telnet1.Send ps + vbCrLf
- Search for command prompt
- Telnet1.Search Data, txtCommandPrompt
- AddResult Data
- Send command
- Telnet1.Send netstat -rn + vbCrLf
- Search for command prompt
- Telnet1.Search Data, txtCommandPrompt
- AddResult Data
- Close the connection
- Telnet1.Close
- If Err.number = 0 then
- AddResult vbCrLf + Disconnecting... SUCCESS!
- Else
- Display info about the error
- AddResult vbcrlf + ERROR # + CStr(Err.number) + : + Err.Description
- End if
- Response.Write Session(RESULT)
- End Sub
- Private Sub AddResult(s)
- Session(RESULT) = Session(RESULT) + ReadyForHtml(s)
- End Sub
- Substitute escape codes for some of the HTML reserved characters
- Function ReadyForHtml(Data)
- On Error Resume Next
- ReadyForHtml = Data
- ReadyForHtml = Replace(ReadyForHtml, , gt;)
- ReadyForHtml = Replace(ReadyForHtml, , lt;)
- ReadyForHtml = Replace(ReadyForHtml, , nbsp;)
- ReadyForHtml = Replace(ReadyForHtml, vbCrLf , brnbsp;)
- ReadyForHtml = Replace(ReadyForHtml, vbCrLf, br)
- End Function
- Dim txtHost
- Dim txtLoginPrompt
- Dim txtUser
- Dim txtPassPrompt
- Dim txtPass
- Dim txtCommandPrompt
- txtHost = 192.0.1.6
- txtLoginPrompt = login:
- txtUser = root
- txtPassPrompt = Password
- txtPass = hp123
- txtCommandPrompt = #
- DoLogin()
Summary
By using the Telnet Tool ActiveX control, we can log on to the UNIX System in the ASP program to easily complete many command line operations. Similarly, we can view the network configuration and running status in the CISCO router and switch through a browser.
Enterprise Firewall settings should generally prohibit direct remote logon from external networks to internal UNIX hosts, but we can simply click on a browser to select a specific operation, the ASP program on the WEB Server is used to log on to the UNIX host to complete the specified operation, which increases the system security while facilitating management.
Of course, we should always consider security issues in ASP programming, especially to avoid accidental leakage of ASP source code and UNIX passwords.