我用自己的扫描器扫不到任何开放端口,单步执行时发现根本没有执行过winsock1_
connect事件 难道没连上吗?是不是我的winsock1.close用的不对,导致不能连接成功。 请大家帮我看看!!Public Sub scan()
startport = Val(txtstart.Text)
stopport = Val(txtstop.Text)
portnum = startport - 1
Do Until portnum = stopport
If ScanOnOff = False Then
Exit Sub
End If
For x = 1 To 1500000 '时间延迟
Next
DoEvents
IPaddr = txtIP.Text
DoEvents
Winsock1.Close
Winsock1.Connect IPaddr, startport
For x = 1 To 1500000
Next
DoEvents
portnum = portnum + 1
For x = 1 To 1500000
Next
DoEvents
Loop
AddText txtlog, vbCrLf & "所有端口扫描完毕!"
End Sub
Private Sub Winsock1_Connect()
AddText txtlog, vbCrLf & Time & "端口" & Winsock1.RemotePort & "开放!" '在txtlog中显示开放的端口号
End Sub
connect事件 难道没连上吗?是不是我的winsock1.close用的不对,导致不能连接成功。 请大家帮我看看!!Public Sub scan()
startport = Val(txtstart.Text)
stopport = Val(txtstop.Text)
portnum = startport - 1
Do Until portnum = stopport
If ScanOnOff = False Then
Exit Sub
End If
For x = 1 To 1500000 '时间延迟
Next
DoEvents
IPaddr = txtIP.Text
DoEvents
Winsock1.Close
Winsock1.Connect IPaddr, startport
For x = 1 To 1500000
Next
DoEvents
portnum = portnum + 1
For x = 1 To 1500000
Next
DoEvents
Loop
AddText txtlog, vbCrLf & "所有端口扫描完毕!"
End Sub
Private Sub Winsock1_Connect()
AddText txtlog, vbCrLf & Time & "端口" & Winsock1.RemotePort & "开放!" '在txtlog中显示开放的端口号
End Sub
Dim portnum As Long
Dim start As String
Dim TimerOnOff As String
Private Sub Command1_Click()
Command2.Enabled = True
If Text1.Text = "" Then
MsgBox "输入开始扫描端口"
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "输入最大扫描端口"
Exit Sub
End IfText1.Locked = True
Text2.Locked = True
Command1.Enabled = False
Winsock1.Close
start = True
logport.Text = " 开始扫描"Call scanningports
logport.Text = logport.Text & vbCrLf & "端口 " & Text1.Text & "- " & Text3.Text & " 被成功扫描."
End SubSub scanningports()
Dim porttwo As Long
portnum = Text1.Text
porttwo = Text2.Text
Command2.Enabled = True
On Error GoTo viriio
Do
portnum = portnum + 1
DoEvents
If start = True Then
Winsock1.Close '关闭当前连接
DoEvents '使程序稳定性加强的手段,可以响应其他事件
Winsock1.LocalPort = portnum
DoEvents
Text3.Text = portnum
Winsock1.Listen '开始侦听
DoEvents
Else '单击停止按钮
portnum = 0
Command1.Enabled = True
Text1.Locked = False
Text2.Locked = False
Exit Sub
End If
Winsock1.Close
DoEvents
Loop Until portnum >= porttwo
portnum = 0
Command1.Enabled = True
logport.Text = logport.Text & vbCrLf & "完成端口扫描!" & vbCrLf
Text1.Locked = False
Text2.Locked = False
viriio: If Err.Number = 10048 Then
logport.Text = logport.Text & vbCrLf & "端口 " & Winsock1.LocalPort & " 已经被使用!"
Resume Next ' 回到出错误的地方
End IfEnd SubPrivate Sub Command2_Click()
Command2.Enabled = False
start = False
End SubPrivate Sub Command3_Click()
Text1.Text = "1"
Text2.Text = "65530"Text1.Locked = True
Text2.Locked = True
Command1.Enabled = False
Winsock1.Close
start = TrueCall scanningports
End Sub
扫描本机端口还是很快的,直接Winsock1.Listen即可使用winsock控件的connect事件。代表winsock控件已经与目标ip特定端口区的连接
而winsock控件的error事件来处理连接端口无响应不过速度还是不理想,应为connect要去尝试连接
Option Explicit
Dim Port As LongPrivate Sub Command1_Click()
Port = CLng(Text2.Text)
Winsock1.Connect Text1.Text, Port
Label4.Caption = "端口:" & Port
End SubPrivate Sub Command2_Click()
Winsock1.Close
Port = CLng(Text2.Text)
End SubPrivate Sub Winsock1_Connect()
Text4.Text = Text4.Text & "端口编号:" & Str(Winsock1.RemotePort) & vbCrLf
Winsock1.Close
Port = Port + 1
If Port <= CLng(Text3.Text) Then
Label4.Caption = "端口:" & Port
Winsock1.Connect Text1.Text, Port
Else
Command2_Click
End If
End SubPrivate 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) Winsock1.Close
Port = Port + 1
If Port <= CLng(Text3.Text) Then
Label4.Caption = "端口:" & Port
Winsock1.Connect Text1.Text, Port
Else
Command2_Click
End If
End Sub
dim NP as long
if 起始端口 = 结束端口 then
winsock.close
exit sub
else
if winsock.state = 7 then
list.additem winsock.remoteport
winsock.close
else
winsock.close
winsock.connect IP , NP
NP = NP + 1
me.caption = np
end if
end if
原理就是这样~~~