Option Explicit
Private host As String
Private port As Integer
Private Sub Form_Load()
host = Trim(InputBox("输入主机地址,端口号用空格分割"))
Text1.Text = ""
Text1.Locked = True
If InStr(host, " ") >0 Then
port = Val(Mid(host, InStr(host, " ") + 1))
host = Left(host, InStr(host, " ") - 1)
End If
If port = 0 Then port = 23
Winsock1.Protocol = sckTCPProtocol
Winsock1.Connect host, port
End Sub
Private Sub Text1_Change()
Text1.SelStart = Len(Text1.Text)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim c As String
c = Chr(KeyAscii)
Winsock1.SendData c
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s() As Byte
Dim l As Long
Winsock1.GetData s
ExplainCode s
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Text1.Text = Text1.Text &vbCrLf &"Connect Error" &vbCrLf
End Sub
Private Function ExplainCode(ByRef s() As Byte) As String
Dim i As Long, j As Long
Dim l As Long
Dim k() As Byte
Dim db() As Byte, dbl As Long
ReDim k(UBound(s)) As Byte
Dim ss As String
dbl = -1
ExplainCode = vbNullChar
For i = 0 To UBound(s)
Select Case s(i)
Case 8
If i <UBound(s) - 1 Then
If s(i + 2) = 8 Then
ss = Left(Text1.Text, Len(Text1.Text) - 1)
Text1.Text = ss
i = i + 2
End If
End If
Case 255
If i <UBound(s) Then
Select Case s(i + 1)
Case 253
If i <UBound(s) - 1 Then
ReDim Preserve db(0 To dbl + 3)
db(dbl + 1) = s(i)
db(dbl + 2) = &HFC '所有特殊请求全部拒绝
db(dbl + 3) = s(i + 2)
dbl = dbl + 3
i = i + 2
End If
Case 250
For j = i To UBound(s)
If s(j) = 240 Then
Exit For
End If
Next j
i = j
Case 251
If i <UBound(s) - 1 Then
i = i + 2
End If
End Select
End If
Case 27
If i <UBound(s) - 1 Then
If s(i + 1) = &H5B Then
If s(i + 2) = &H48 Then
Text1.Text = Text1.Text &vbCrLf
i = i + 2
ElseIf s(i + 2) = &H4A Then
Text1.Text = ""
i = i + 2
Else
For j = i To UBound(s)
If s(j) = 109 Or s(j) = 75 Or s(j) = 74 Then
Exit For
End If
Next j
i = j
End If
End If
End If
Case Else
If i <UBound(s) Then
If s(i) = 10 And s(i + 1) = 13 Then
s(i) = 13
s(i + 1) = 10
End If
End If
k(l) = s(i)
l = l + 1
End Select
Next i
If dbl <>-1 Then Winsock1.SendData db
If l = 0 Then Exit Function
ReDim Preserve k(0 To l - 1) As Byte
ExplainCode = StrConv(k, vbUnicode)
Text1.Text = Text1.Text &ExplainCode
End Function
Linux 下流行的 telnet 实现有两个:GNU 的 inetutils 中的实现 [1]
哈佛的 netkit-telnet [2]
1. http://ftp.gnu.org/gnu/inetutils/
2. http://ftp.de.debian.org/debian/pool/main/n/netkit-telnet/netkit-telnet_0.17.orig.tar.gz
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)