Dim Socket As Variant
Dim CurrentPort As Integer
Const MaxSockets = 200
On Error Resume Next
If Command1.Caption = "开始" Then
Command1.Caption = "停止"
For i = 1 To MaxSockets
Load Sock(i)
Next i
CurrentPort = txtPortStart.Text
While Command1.Caption = "停止"
For Each Socket In Sock
DoEvents
If Socket.State <> sckClosed Then
GoTo continue
End If
Socket.Close
If CurrentPort = Val(txtPortEnd.Text) + 1 _
Then Exit For
Socket.RemoteHost = txtHost.Text
Socket.RemotePort = CurrentPort
Text1.Text = "正在扫描IP " & txtHost & " 的端口 当前端口 " & CurrentPort
Socket.Connect
CurrentPort = CurrentPort + 1
continue:
Next Socket
Wend
Command1.Caption = "开始"
txtHost.Enabled = True
txtPortStart.Enabled = True
txtPortEnd.Enabled = True
Else
Command1.Caption = "开始"
End If
For i = 1 To MaxSockets
Unload Sock(i)
Next i
Private Sub FoundPorts_Change()
FoundPorts.SelStart = Len(FoundPorts.Text)
End Sub
Private Function AddPort(port As Integer)
FoundPorts.Text = FoundPorts.Text & txtHost & " → " & port & " 端口开放" & vbCrLf
End Function
Private Sub Sock_Connect(Index As Integer)
AddPort (Sock(Index).RemotePort)
Sock(Index).Close
End Sub