📄 form1.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1
Caption = "端口扫描程序"
ClientHeight = 3435
ClientLeft = 165
ClientTop = 555
ClientWidth = 4440
Icon = "Form1.frx":0000
LinkTopic = "Form1"
ScaleHeight = 3435
ScaleWidth = 4440
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "扫描可能端口"
Height = 375
Left = 2880
TabIndex = 9
Top = 840
Width = 1335
End
Begin VB.TextBox logport
BackColor = &H00FFFFFF&
ForeColor = &H000000C0&
Height = 1935
Left = 120
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 5
Text = "Form1.frx":000C
Top = 720
Width = 2655
End
Begin VB.TextBox Text3
BackColor = &H00FFFFFF&
ForeColor = &H000000C0&
Height = 285
Left = 1440
TabIndex = 4
Top = 3000
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "停止扫描"
Enabled = 0 'False
Height = 375
Left = 2880
TabIndex = 3
Top = 2160
Width = 1335
End
Begin MSWinsockLib.Winsock Winsock1
Left = 3840
Top = 3000
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.TextBox Text2
BackColor = &H00000000&
ForeColor = &H0080FFFF&
Height = 285
Left = 3240
TabIndex = 2
Text = "65530"
Top = 360
Width = 855
End
Begin VB.TextBox Text1
BackColor = &H00000000&
ForeColor = &H0080FFFF&
Height = 285
Left = 1680
TabIndex = 1
Text = "1"
Top = 360
Width = 855
End
Begin VB.CommandButton Command1
Caption = "开始扫描"
Height = 375
Left = 2880
TabIndex = 0
Top = 1560
Width = 1335
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "正在扫描端口"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 255
Left = 120
TabIndex = 8
Top = 3000
Width = 1695
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "---------"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 255
Left = 2640
TabIndex = 7
Top = 360
Width = 495
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "端口扫描范围:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 255
Left = 240
TabIndex = 6
Top = 360
Width = 1455
End
Begin VB.Image Image1
Height = 1785
Index = 0
Left = 0
Top = 0
Width = 4425
End
Begin VB.Image Image1
Height = 1785
Index = 1
Left = 0
Top = 1680
Width = 4425
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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 If
Text1.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 Sub
Sub 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 If
End Sub
Private Sub Command2_Click()
Command2.Enabled = False
start = False
End Sub
Private Sub Command3_Click()
Text1.Text = "1"
Text2.Text = "65530"
Text1.Locked = True
Text2.Locked = True
Command1.Enabled = False
Winsock1.Close
start = True
Call scanningports
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -