Telnet Tool ActiveX控件應(yīng)用實(shí)例代碼
在網(wǎng)站建設(shè)過程中,我們可以應(yīng)用Telnet Tool ActiveX來進(jìn)行一些編程。對(duì)于Telnet Tool ActiveX控件的功能我們?cè)谇耙黄恼轮幸呀?jīng)介紹過了。那么下面我們就來對(duì)這方面進(jìn)行一下應(yīng)用舉例。
編程實(shí)例
下面是一個(gè)簡(jiǎn)單的Telnet Tool ActiveX控件的ASP編程實(shí)例。 實(shí)驗(yàn)環(huán)境是: Windows 2000 Professional、IIS 5.0、SCO OpenServer 5.0.2和Telnet Tool ActiveX控件。Telnet Tool ActiveX控件可以在www.dart.com下載30天試用版,只需要安裝在WEB服務(wù)器上。
程序并不復(fù)雜,登錄到一個(gè)SCO UNIX系統(tǒng)后,執(zhí)行了2條命令,命令的結(jié)果顯示在瀏覽器頁面上。
- 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()
小結(jié)
通過使用Telnet Tool ActiveX控件,我們可以在ASP程序中登錄到UNIX系統(tǒng)上,輕松地完成很多命令行操作。類似的,我們也可以實(shí)現(xiàn)通過瀏覽器查看CISCO路由器、交換機(jī)中的網(wǎng)絡(luò)配置和運(yùn)行狀態(tài)。
企業(yè)的防火墻設(shè)置一般來說應(yīng)該禁止從外部網(wǎng)直接遠(yuǎn)程登錄到內(nèi)部的UNIX主機(jī)上,但是我們可以通過在瀏覽器上簡(jiǎn)單的點(diǎn)擊選擇特定的操作,由WEB Server端的ASP程序登錄到UNIX主機(jī)上完成指定操作,在方便管理的同時(shí)增加了系統(tǒng)的安全性。
當(dāng)然,我們?cè)贏SP編程中應(yīng)該隨時(shí)考慮到安全性問題,尤其是要避免不慎造成的ASP源代碼和UNIX口令的泄露。