2 Begin VB.Form frmTelnet
\r
3 BackColor = &H80000017&
\r
4 BorderStyle = 0 'None
\r
9 FillColor = &H00800000&
\r
15 Underline = 0 'False
\r
17 Strikethrough = 0 'False
\r
19 ForeColor = &H0000FFFF&
\r
20 KeyPreview = -1 'True
\r
22 MaxButton = 0 'False
\r
23 MinButton = 0 'False
\r
24 PaletteMode = 1 'UseZOrder
\r
27 ShowInTaskbar = 0 'False
\r
28 Begin VB.Timer cursor_timer
\r
35 Attribute VB_Name = "frmTelnet"
\r
36 Attribute VB_GlobalNameSpace = False
\r
37 Attribute VB_Creatable = False
\r
38 Attribute VB_PredeclaredId = True
\r
39 Attribute VB_Exposed = False
\r
48 Const SE = 240 'End of Subnegotiation
\r
49 Const SB = 250 'What follows is subnegotiation
\r
62 Const TERMSPEED = 32
\r
63 Const TFLOWCNTRL = 33
\r
67 Const AUTHENTICATION = 37
\r
68 Const UNKNOWN39 = 39
\r
69 Public Receiving As Boolean
\r
70 Private parsedata(10) As Integer
\r
71 Private ppno As Integer
\r
72 Private control_on As Boolean
\r
73 Private sw_ugoahead As Boolean
\r
74 Private sw_igoahead As Boolean
\r
75 Private sw_echo As Boolean
\r
76 Private sw_termsent As Boolean
\r
77 '------------------------------------------------------------
\r
78 Public Telnet_Connectado As Boolean
\r
79 Public WithEvents Socket As CSocketMaster
\r
80 Attribute Socket.VB_VarHelpID = -1
\r
82 Private Sub cursor_timer_Timer()
\r
84 On Error Resume Next
\r
87 If Not Receiving Then term_DriveCursor
\r
90 Private Sub Form_KeyDown(KeyCode As Integer, _
\r
93 On Error GoTo Form_KeyDown_Err
\r
98 'Translate keycodes to VT100 escape sequences
\r
99 101 Select Case KeyCode
\r
102 102 control_on = True
\r
105 104 CH = Chr$(27) + "[K"
\r
108 106 CH = Chr$(27) + "[H"
\r
111 108 CH = Chr$(27) + "[D"
\r
114 110 CH = Chr$(27) + "[A"
\r
116 111 Case vbKeyRight
\r
117 112 CH = Chr$(27) + "[C"
\r
120 114 CH = Chr$(27) + "[B"
\r
123 116 CH = Chr$(27) + "OP"
\r
126 118 CH = Chr$(27) + "OQ"
\r
129 120 CH = Chr$(27) + "OR"
\r
132 122 CH = Chr$(27) + "OS"
\r
136 124 If control_on And KeyCode > 63 Then
\r
137 125 CH = Chr$(KeyCode - 64)
\r
142 126 If CH > Chr$(0) And Telnet_Connectado Then Socket.SendData CH
\r
147 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.Form_KeyDown.Ref 12/2/2008 : 09:38:36"
\r
152 Private Sub Form_KeyPress(KeyAscii As Integer)
\r
154 On Error GoTo Form_KeyPress_Err
\r
158 100 If Telnet_Connectado Then
\r
159 101 CH = Chr$(KeyAscii)
\r
161 102 If control_on Then
\r
162 103 If KeyAscii > 63 Then
\r
163 104 CH = Chr$(KeyAscii - 64)
\r
169 106 If CH > Chr$(0) Then
\r
170 107 If CH = Chr$(13) Then
\r
171 108 CH = CH & Chr$(10)
\r
174 109 Socket.SendData CH
\r
182 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.Form_KeyPress.Ref 12/2/2008 : 09:38:36"
\r
187 Private Sub Form_KeyUp(KeyCode As Integer, _
\r
190 On Error GoTo Form_KeyUp_Err
\r
193 100 Select Case KeyCode
\r
196 101 control_on = False
\r
203 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.Form_KeyUp.Ref 12/2/2008 : 09:38:36"
\r
208 Private Sub Form_Load()
\r
210 On Error GoTo Form_Load_Err
\r
212 100 Set Socket = New CSocketMaster
\r
218 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.Form_Load.Ref 12/2/2008 : 09:38:36"
\r
223 Private Sub Form_Paint()
\r
225 On Error GoTo Form_Paint_Err
\r
227 100 term_redrawscreen
\r
232 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.Form_Paint.Ref 12/2/2008 : 09:38:36"
\r
237 Private Sub Form_QueryUnload(Cancel As Integer, _
\r
238 UnloadMode As Integer)
\r
240 On Error GoTo Form_QueryUnload_Err
\r
244 101 .CloseSck ' Clear any errors...
\r
245 102 .RemoteHost = "0.0.0.0"
\r
246 103 .RemotePort = 0
\r
249 104 Telnet_Connectado = False
\r
253 Form_QueryUnload_Err:
\r
254 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.Form_QueryUnload.Ref 12/2/2008 : 09:38:36"
\r
259 Private Sub Socket_CloseSck()
\r
261 On Error GoTo Socket_CloseSck_Err
\r
263 100 Telnet_Connectado = False
\r
266 Socket_CloseSck_Err:
\r
267 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.Socket_CloseSck.Ref 12/2/2008 : 09:38:36"
\r
272 Private Sub Socket_Connect()
\r
274 On Error GoTo Socket_Connect_Err
\r
276 Dim ConnectString As String
\r
277 '------------------------------------------------------------
\r
278 100 sw_ugoahead = True
\r
279 101 sw_igoahead = False
\r
281 103 sw_termsent = False
\r
282 104 ConnectString = Chr$(IAC) & Chr$(DOTEL) & Chr$(ECHO) & Chr$(IAC) & Chr$(DOTEL) & Chr$(SGA) & Chr$(IAC) & Chr$(WILLTEL) & Chr$(NAWS) & Chr$(IAC) & Chr$(WILLTEL) & Chr$(TERMTYPE) & Chr$(IAC) & Chr$(WILLTEL) & Chr$(TERMSPEED)
\r
283 105 Socket.SendData ConnectString
\r
284 106 Telnet_Connectado = True
\r
287 Socket_Connect_Err:
\r
288 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.Socket_Connect.Ref 12/2/2008 : 09:38:36"
\r
293 Private Sub Socket_DataArrival(ByVal bytesTotal As Long)
\r
295 On Error GoTo Socket_DataArrival_Err
\r
301 '------------------------------------------------------------
\r
302 100 If Receiving Then
\r
305 101 Receiving = True
\r
306 102 term_CaretControl True
\r
309 103 If (bytesTotal > 0) Then ' If there is any data...
\r
310 104 Socket.GetData CH, vbByte + vbArray, bytesTotal
\r
311 105 bytesTotal = bytesTotal - 1
\r
314 106 For i = 0 To bytesTotal
\r
316 107 Select Case cmd
\r
319 108 cmd = term_process_char(CH(i))
\r
322 110 cmd = iac1(CH(i))
\r
325 112 cmd = iac2(CH(i))
\r
328 114 cmd = iac3(CH(i))
\r
331 116 cmd = iac4(CH(i))
\r
334 118 cmd = iac5(CH(i))
\r
337 120 cmd = iac6(CH(i))
\r
344 'Enviamos el siguiente comando
\r
345 121 If nComando < UBound(TelnetComandos) And Socket.State = sckConnected Then
\r
346 122 Socket.SendData TelnetComandos(nComando) & vbCrLf
\r
347 123 Registrar "Telnet -> Enviado: " & TelnetComandos(nComando)
\r
348 124 nComando = nComando + 1
\r
351 125 term_CaretControl False
\r
352 126 Receiving = False
\r
355 Socket_DataArrival_Err:
\r
356 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.Socket_DataArrival.Ref 12/2/2008 : 09:38:36"
\r
361 Private Function iac1(CH As Byte) As Integer
\r
362 ' Debug.Print "IAC : ";
\r
364 On Error GoTo iac1_Err
\r
388 ' End of negotiation string, string is in parsedata()
\r
389 113 Select Case parsedata(0)
\r
393 114 If parsedata(1) = 1 Then
\r
394 115 Socket.SendData Chr$(IAC) & Chr$(SB) & Chr$(TERMTYPE) & "DEC-VT100" & Chr$(0) & Chr$(IAC) & Chr$(SE)
\r
399 117 If parsedata(1) = 1 Then
\r
400 ' Debug.Print "TERMSPEED"
\r
401 118 Socket.SendData Chr$(IAC) & Chr$(WILLTEL) & Chr$(CH)
\r
402 119 Socket.SendData Chr$(IAC) & Chr$(SB) & Chr$(TERMSPEED) & Chr$(0) & "57600,57600" & Chr$(IAC) & Chr$(SE)
\r
411 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.iac1.Ref 12/2/2008 : 09:38:36"
\r
416 Private Function iac2(CH As Byte) As Integer
\r
417 'DO Processing Respond with WILL or WONT
\r
419 On Error GoTo iac2_Err
\r
428 103 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(BINARY)
\r
431 105 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(ECHO)
\r
434 107 .SendData Chr$(IAC) & Chr$(SB) & Chr$(NAWS) & Chr$(0) & Chr$(80) & Chr$(0) & Chr$(24) & Chr$(IAC) & Chr$(SE)
\r
438 109 If Not sw_igoahead Then
\r
439 110 .SendData Chr$(IAC) & Chr$(WILLTEL) & Chr$(SGA)
\r
440 111 sw_igoahead = True
\r
445 113 If Not sw_termsent Then
\r
446 114 sw_termsent = True
\r
447 115 .SendData Chr$(IAC) & Chr$(WILLTEL) & Chr$(TERMTYPE)
\r
448 116 .SendData Chr$(IAC) & Chr$(SB) & Chr$(TERMTYPE) & Chr$(0) & "VT100" & Chr$(IAC) & Chr$(SE)
\r
452 118 .SendData Chr$(IAC) & Chr$(WILLTEL) & Chr$(TERMSPEED)
\r
453 119 .SendData Chr$(IAC) & Chr$(SB) & Chr$(TERMSPEED) & Chr$(0)
\r
454 120 .SendData "57600,57600"
\r
455 121 .SendData Chr$(IAC) & Chr$(SE)
\r
457 122 Case TFLOWCNTRL
\r
458 123 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
461 125 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
464 127 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
467 129 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
470 131 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
473 133 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
476 135 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
478 136 Case AUTHENTICATION
\r
479 137 .SendData Chr$(IAC) & Chr$(WILLTEL) & Chr$(CH)
\r
480 138 .SendData Chr$(IAC) & Chr$(SB) & Chr$(AUTHENTICATION) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(IAC) & Chr$(SE)
\r
483 140 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
491 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.iac2.Ref 12/2/2008 : 09:38:36"
\r
496 Private Function iac3(CH As Byte) As Integer
\r
497 ' WILL Processing - Respond with DO or DONT
\r
499 On Error GoTo iac3_Err
\r
509 103 If Not sw_echo Then
\r
511 105 .SendData Chr$(IAC) & Chr$(DOTEL) & Chr$(ECHO)
\r
516 107 If Not sw_ugoahead Then
\r
517 108 sw_ugoahead = True
\r
518 109 .SendData Chr$(IAC) & Chr$(DOTEL) & Chr$(SGA)
\r
522 111 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
524 112 Case TFLOWCNTRL
\r
525 113 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
528 115 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
531 117 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
534 119 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
537 121 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
540 123 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
543 125 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
546 127 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
554 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.iac3.Ref 12/2/2008 : 09:38:36"
\r
559 Private Function iac4(CH As Byte) As Integer
\r
562 On Error GoTo iac4_Err
\r
572 103 If sw_echo = True Then
\r
573 104 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(ECHO)
\r
574 105 sw_echo = False
\r
578 107 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(SGA)
\r
579 108 sw_igoahead = False
\r
582 110 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
584 111 Case TFLOWCNTRL
\r
585 112 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
588 114 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
591 116 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
594 118 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
597 120 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
600 122 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
603 124 .SendData Chr$(IAC) & Chr$(DONTTEL) & Chr$(CH)
\r
606 126 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
614 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.iac4.Ref 12/2/2008 : 09:38:36"
\r
619 Private Function iac5(CH As Byte) As Integer
\r
621 On Error GoTo iac5_Err
\r
624 ' Collect parms after SB and until another IAC
\r
627 101 If ich = IAC Then
\r
632 103 parsedata(ppno) = ich
\r
633 104 ppno = ppno + 1
\r
638 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.iac5.Ref 12/2/2008 : 09:38:36"
\r
643 Private Function iac6(CH As Byte) As Integer
\r
646 On Error GoTo iac6_Err
\r
659 104 If Not sw_echo Then
\r
661 106 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(ECHO)
\r
666 108 If Not sw_ugoahead Then
\r
667 109 sw_ugoahead = True
\r
668 110 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(SGA)
\r
672 112 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
674 113 Case TFLOWCNTRL
\r
675 114 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
678 116 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
681 118 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
684 120 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
687 122 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
690 124 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
693 126 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
696 128 .SendData Chr$(IAC) & Chr$(WONTTEL) & Chr$(CH)
\r
704 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.iac6.Ref 12/2/2008 : 09:38:36"
\r
709 Private Sub SOCKET_ERROR(ByVal Number As Integer, _
\r
710 Description As String, _
\r
711 ByVal sCode As Long, _
\r
712 ByVal Source As String, _
\r
713 ByVal HelpFile As String, _
\r
714 ByVal HelpContext As Long, _
\r
715 CancelDisplay As Boolean)
\r
717 On Error GoTo SOCKET_ERROR_Err
\r
720 100 If Number <> 10053 Then
\r
721 101 NetError = True
\r
722 102 Registrar "Telnet -> (" & Number & ") " & Description
\r
724 103 Registrar "Telnet -> Bien, el router abandonó la conexión"
\r
730 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.SOCKET_ERROR.Ref 12/2/2008 : 09:38:36"
\r
735 Public Sub ProcTelnet()
\r
737 On Error GoTo ProcTelnet_Err
\r
739 100 Registrar "~ProcTelnet - Nivel 1"
\r
743 103 .RemotePort = m_Datos.puerto
\r
744 104 .RemoteHost = m_Datos.base
\r
745 105 .Protocol = sckTCPProtocol
\r
748 108 Registrar "~ProcTelnet - Nivel 2"
\r
750 109 Do Until Telnet_Connectado Or NetError
\r
754 111 Registrar "~ProcTelnet - Nivel 3"
\r
760 Controlar_Error Erl, Err.Description, "Reseter.frmTelnet.ProcTelnet.Ref 12/2/2008 : 09:38:36"
\r