'本地不可用 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Delay(PauseTime As Long) '防止假死 Dim Start As Single Start = Timer * 1000 Do While Timer * 1000 < Start + PauseTime Sleep (1) DoEvents Loop End Sub
Private Sub Command1_Click() Dim i As Long Winsock1.Close Winsock1.RemoteHost = Text1.Text '要扫描的IP For i = 0 To 65536 '端口号只有整数,范围是从0 到65535(2^16-1) Winsock1.RemotePort = i Winsock1.Connect Delay 500 If Winsock1.State = 7 Then '连接是否成功 List1.AddItem i End If Next End Sub