信息来源:黑客防线
复制内容到剪贴板
代码:
'本程序在VB6.0+Windows2000下测试通过!
Dim tmpstr As String
Dim NOW_OUT As Integer '总共出去连接的有几个Winsock
Private Sub Command1_Click()
ListPorts.AddItem txtADDPORT.Text
End Sub
Private Sub Command2_Click()
On Error Resume Next
If Command2.Caption = "监听" Then
For i = 0 To ListPorts.ListCount - 1
Load Winsock1(i + 1) '加载监听端口的winsock1数组控件
Winsock1(i + 1).LocalPort = ListPorts.List(i) '设定端口
Winsock1(i + 1).Listen '监听
Next i
Command2.Caption = "停止"
Else
For i = 1 To Winsock1.Count - 1
Unload Winsock1(i)
Next i
For i2 = 1 To Winsock2.Count - 1
Unload Winsock2(i2)
Next i2
Command2.Caption = "监听"
End If
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
txtLOG.Text = "日志:" & vbCrLf
NOW_OUT = 1
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Load Winsock2(NOW_OUT) '加载建立连接的Winsock2数组控件
Winsock2(NOW_OUT).Accept requestID '建立连接
Winsock1(Index).Close
Winsock1(Index).Listen 'Winsock1继续监听
NOW_OUT = NOW_OUT + 1 '连接的控件累加
myAddLog "来自" & Winsock1(Index).RemoteHostIP & "连接到本地端口:" & Winsock1(Index).LocalPort
'显示捕获的连接
End Sub
Private Sub Winsock2_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Winsock2(Index).GetData tmpstr '通过Getdata捕获数据
myAddLog "来自" & Winsock2(Index).RemoteHostIP & "的数据:" & tmpstr '显示捕获的数据
End Sub
Sub myAddLog(tmptext As String) '加入日志
tmptext = tmptext & vbCrLf
txtLOG.SelStart = Len(txtLOG.Text)
txtLOG.SelText = tmptext
End Sub