ASP程序中使用Telnet协议
| 首 页 | 网页素材 | 网页特效 | 网页教程 | flash教程 | 3dmax教程 | ASP教程 | 常用范文 | 应用公文 |
教 程 | 频道首页 | flash教程 | 3dmax教程 | photoshop教程 | html/css | asp教程 | php教程 | fireworks教程 | dreamweaver教程|
资 料 | java教程 | 网页模版 | 搜索引擎 | 电脑技术 | 网络应用 | 操作系统 | 饮食文化 | 应用公文 | 贺词致辞 | 个人求职 |
频 道 | 明星资料 | 民俗风情 | 传统节日 | 人物传记 | 历史资料 | 常用范文 | 名胜古迹 | 体育资料 | 教育资料 | 综合资料 |
你的位置:首页 > 资料教程 > 正文 > ASP程序中使用Telnet协议
ASP程序中使用Telnet协议

http://www.sucai123.com 资料教程 2004-10-5 22:37:10
>' 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, ">", ">")
ReadyForHtml = Replace(ReadyForHtml, "<", "&lt;")
ReadyForHtml = Replace(ReadyForHtml, " ", "&nbsp;")
ReadyForHtml = Replace(ReadyForHtml, vbCrLf & " ", "<br>&nbsp;")
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()
%>

</BODY>
</HTML>

5 小结

通过使用Telnet Tool ActiveX控件,我们可以在ASP程序中登录到UNIX系统上,轻松地完成很多命令行操作。类似的,我们也可以实现通过浏览器查看CISCO路由器、交换机中的网络配置和运行状态。

企业的防火墙设置一般来说应该禁止从外部网直接远程登录到内部的UNIX主机上,但是我们可以通过在浏览器上简单的点击选择特定的操作,由WEB Server端的ASP程序登录到UNIX主机上完成指定操作,在方便管理的同时增加了系统的安全性。

当然,我们在ASP编程中应该随时考虑到安全性问题,尤其是要避免不慎造成的ASP源代码和UNIX口令的泄露。

此新闻共有21 2


-来源:互联网 关闭 ASP程序中使用Telnet协议】
∷∷ 相 关 文 章 ∷∷
·asp的19个基本技巧
·asp的19个基本技巧
·ASP中使用SQL语句操作数据库
·用ASP学做一个在线调查
·ASP的含义、功能和选择
·ASP编写计数器的优化方法
·ASP程序中使用Telnet协议
·asp 应用程序成为 exe 文件
∷∷ 热 门 推 荐 ∷∷