Telnet Tool ActiveX control application instance code

Source: Internet
Author: User

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.

 
 
  1. HTML  
  2. HEADTITLEPowerTCP Telnet Tool Demo Page/TITLE/HEAD  
  3. BODY  
  4. *******************************************************************  
  5. Program: PowerTCP Telnet Tool Demo  
  6. Author: Yin  
  7. Date: 07/16/2001  
  8. Purpose: To demonstrate how to login into a SCO UNIX server.  
  9. ********************************************************************}  
  10. Sub DoLogin()   
  11. Session(RESULT) =   
  12. On Error Resume Next   
  13. Create a Telnet control   
  14. Dim Telnet1   
  15. Set Telnet1 = Server.CreateObject(Dart.Telnet.1)   
  16. Use a 10 second timeout   
  17. Telnet1.Timeout = 10000   
  18. Specifies terminal type   
  19. Telnet1.TermType = ansi   
  20. AddResult Connecting to + txtHost + ... + vbCrLf   
  21. Connect to the host on port 23   
  22. Telnet1.Connect txtHost,23   
  23. Dim a string to be used by the search method   
  24. Dim Data   
  25. Data =   
  26. Search for login prompt   
  27. Telnet1.Search Data, txtLoginPrompt   
  28. AddResult Data   
  29. Send username   
  30. Telnet1.Send txtUser + vbCrLf   
  31. Search for password prompt   
  32. Telnet1.Search Data, txtPassPrompt   
  33. AddResult Data   
  34. Send password   
  35. Telnet1.Send txtPass + vbCrLf + vbCrLf   
  36. Search for command prompt   
  37. Telnet1.Search Data, txtCommandPrompt   
  38. AddResult Data   
  39. Send command   
  40. Telnet1.Send ps + vbCrLf   
  41. Search for command prompt   
  42. Telnet1.Search Data, txtCommandPrompt   
  43. AddResult Data   
  44. Send command   
  45. Telnet1.Send netstat -rn + vbCrLf   
  46. Search for command prompt   
  47. Telnet1.Search Data, txtCommandPrompt   
  48. AddResult Data   
  49. Close the connection   
  50. Telnet1.Close   
  51. If Err.number = 0 then   
  52. AddResult vbCrLf + Disconnecting... SUCCESS!   
  53. Else   
  54. Display info about the error   
  55. AddResult vbcrlf + ERROR # + CStr(Err.number) + : + Err.Description   
  56. End if   
  57. Response.Write Session(RESULT)   
  58. End Sub   
  59. Private Sub AddResult(s)   
  60. Session(RESULT) = Session(RESULT) + ReadyForHtml(s)   
  61. End Sub   
  62. Substitute escape codes for some of the HTML reserved characters   
  63. Function ReadyForHtml(Data)   
  64. On Error Resume Next   
  65. ReadyForHtml = Data   
  66. ReadyForHtml = Replace(ReadyForHtml, , gt;)   
  67. ReadyForHtml = Replace(ReadyForHtml, , lt;)   
  68. ReadyForHtml = Replace(ReadyForHtml, , nbsp;)   
  69. ReadyForHtml = Replace(ReadyForHtml, vbCrLf , brnbsp;)   
  70. ReadyForHtml = Replace(ReadyForHtml, vbCrLf, br)   
  71. End Function   
  72. Dim txtHost   
  73. Dim txtLoginPrompt   
  74. Dim txtUser   
  75. Dim txtPassPrompt   
  76. Dim txtPass   
  77. Dim txtCommandPrompt   
  78. txtHost = 192.0.1.6   
  79. txtLoginPrompt = login:   
  80. txtUser = root   
  81. txtPassPrompt = Password   
  82. txtPass = hp123   
  83. txtCommandPrompt = #   
  84. 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.

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.