How to use the Telnet protocol in an ASP program

Source: Internet
Author: User
Tags format end iis connect string access port number visual studio
Program

  1 Design Background

More and more enterprises have chosen the architecture based on Microsoft when they build their own web sites. The Windows operating system, IIS WEB Server, and ASP technologies are widely used. But many enterprise networks have a large number of UNIX hosts, causing us to often want to access and control UNIX system resources in browsers, such as viewing user processes in Unix systems through browsers, viewing network status, or even completing control operations such as killing a process. Previously we could log on to a UNIX host by Telnet program, enter a username and password, and enter a command at the command line. By programming ActiveX controls in ASP, we can also use the Telnet protocol to access UNIX hosts, so that the resources in the UNIX system can be more fully utilized in the B/s environment.

  2 Features of the control

The control that this article describes is a Telnet Tool ActiveX control in the POWERTCP Tools control group developed by the Dart Communications company in the United States. It supports development environments such as visual Studio, ASP, Office (VBA), C++builder, Delphi, PowerBuilder, and so on.

It manages Telnet, rsh, rexec, and Rlogin connections, provides methods for establishing, using, and terminating sessions, supports automatic option negotiation, such as terminal type, echo mode, window size, and so on, users don't care about protocol implementation details, and greatly simplifies the programming difficulty of using these protocols. Control can directly telnet to devices such as UNIX hosts, routers, terminal servers, and support indirect telnet access.

  ASP programming method of 3 control

Telnet Tool The use of ActiveX controls is extremely simple, and its main properties and methods are described below.

TermType property: Specifies the terminal type, such as ANSI, VT320, and so on, to notify the UNIX host client of the type of terminal being emulated.

Timeout property: When set to a value of 0, the control uses Non-blocking to control the session. When set to a value greater than 0, the control uses blocking to control the session, and timeout indicates a time-out in milliseconds.

State property: Returns the TCP connection status.

Connect method: Establish a connection, in the form of:

Object.connect remotename [, RemotePort] [, LocalName] [, LocalPort]. Where RemoteName is the name or IP address of the UNIX host to which you want to connect. RemotePort is the port number for the UNIX host to be connected by default of 23, which is the standard Telnet port. LocalName and LocalPort are local host names and ports, which can generally be omitted.

Close method: Closes a connection, formatted as Object.close

Send method: Sends the data after the connection is established. The format is:

Object.send Data. Data is what you want to send to the UNIX host.

Serach method: Accepts the data returned by the UNIX host and looks for the specified end flag in the data stream, including all return data until the end flag. A timeout error occurs if the specified end flag is not received within the time allotted by timeout. The format is: Object.search Data,token. Data to save the return result, token specifies the end tag string.

  4 Programming examples

The following is an ASP programming instance of a simple Telnet Tool ActiveX control. The experimental environment is: Windows Professional, IIS 5.0, SCO OpenServer 5.0.2, and Telnet Tool ActiveX controls. Telnet Tool ActiveX controls can download a 30-day trial version of www.dart.com, only to be installed on a Web server.

The program is not complex, after logging into a SCO UNIX system, executed 2 commands, the results of the command display 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 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 ten 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 is 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 () 5 Summary

By using Telnet to Tool ActiveX controls, we can log on to UNIX systems in an ASP program and easily complete many command-line operations. Similarly, we can view the network configuration and running status in Cisco routers, switches through browsers.

The enterprise's firewall settings should generally prohibit telnet directly from the extranet to the internal UNIX host, but we can select specific actions by simply clicking on the browser, and logging on to the UNIX host by the ASP program on the Web server to complete the specified operation, It is easy to manage and increase the security of the system.

Of course, we should always consider the security issues in ASP programming, especially to avoid inadvertently caused by the ASP source code and UNIX password leakage.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.