⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 Visual.Basic.NET实用编程百例-47.6M.zip
💻 VB
字号:
Friend Class Form1
    Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
    Public Sub New()
        MyBase.New()
        '此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()
    End Sub
    '窗体重写处置,以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
        If Disposing Then
            If Not components Is Nothing Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(Disposing)
    End Sub
    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer
    Public WithEvents cmdExit As System.Windows.Forms.Button
    Public WithEvents cmdStopScan As System.Windows.Forms.Button
    Public WithEvents txtEndingPort As System.Windows.Forms.TextBox
    Public WithEvents txtStartingPort As System.Windows.Forms.TextBox
    Public WithEvents txtIP As System.Windows.Forms.TextBox
    Public WithEvents List1 As System.Windows.Forms.ListBox
    Public WithEvents cmdStartScan As System.Windows.Forms.Button
    Public WithEvents Winsock1 As AxMSWinsockLib.AxWinsock
    Public WithEvents Label3 As System.Windows.Forms.Label
    Public WithEvents Label2 As System.Windows.Forms.Label
    Public WithEvents Label1 As System.Windows.Forms.Label
    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器来修改它。
    '不要使用代码编辑器来修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.txtEndingPort = New System.Windows.Forms.TextBox
        Me.txtStartingPort = New System.Windows.Forms.TextBox
        Me.txtIP = New System.Windows.Forms.TextBox
        Me.cmdExit = New System.Windows.Forms.Button
        Me.cmdStopScan = New System.Windows.Forms.Button
        Me.List1 = New System.Windows.Forms.ListBox
        Me.cmdStartScan = New System.Windows.Forms.Button
        Me.Winsock1 = New AxMSWinsockLib.AxWinsock
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        CType(Me.Winsock1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'txtEndingPort
        '
        Me.txtEndingPort.AcceptsReturn = True
        Me.txtEndingPort.AutoSize = False
        Me.txtEndingPort.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.txtEndingPort.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtEndingPort.ForeColor = System.Drawing.Color.Black
        Me.txtEndingPort.Location = New System.Drawing.Point(304, 40)
        Me.txtEndingPort.MaxLength = 0
        Me.txtEndingPort.Name = "txtEndingPort"
        Me.txtEndingPort.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtEndingPort.Size = New System.Drawing.Size(93, 22)
        Me.txtEndingPort.TabIndex = 4
        Me.txtEndingPort.Text = ""
        Me.txtEndingPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'txtStartingPort
        '
        Me.txtStartingPort.AcceptsReturn = True
        Me.txtStartingPort.AutoSize = False
        Me.txtStartingPort.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.txtStartingPort.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtStartingPort.ForeColor = System.Drawing.Color.Black
        Me.txtStartingPort.Location = New System.Drawing.Point(176, 40)
        Me.txtStartingPort.MaxLength = 0
        Me.txtStartingPort.Name = "txtStartingPort"
        Me.txtStartingPort.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtStartingPort.Size = New System.Drawing.Size(94, 22)
        Me.txtStartingPort.TabIndex = 3
        Me.txtStartingPort.Text = ""
        Me.txtStartingPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'txtIP
        '
        Me.txtIP.AcceptsReturn = True
        Me.txtIP.AutoSize = False
        Me.txtIP.BackColor = System.Drawing.SystemColors.Control
        Me.txtIP.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtIP.ForeColor = System.Drawing.Color.Black
        Me.txtIP.Location = New System.Drawing.Point(16, 40)
        Me.txtIP.MaxLength = 0
        Me.txtIP.Name = "txtIP"
        Me.txtIP.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtIP.Size = New System.Drawing.Size(120, 22)
        Me.txtIP.TabIndex = 2
        Me.txtIP.Text = ""
        Me.txtIP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'cmdExit
        '
        Me.cmdExit.BackColor = System.Drawing.SystemColors.Control
        Me.cmdExit.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdExit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdExit.Location = New System.Drawing.Point(296, 288)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdExit.Size = New System.Drawing.Size(94, 29)
        Me.cmdExit.TabIndex = 6
        Me.cmdExit.Text = "退出"
        '
        'cmdStopScan
        '
        Me.cmdStopScan.BackColor = System.Drawing.SystemColors.Control
        Me.cmdStopScan.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdStopScan.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdStopScan.Location = New System.Drawing.Point(168, 288)
        Me.cmdStopScan.Name = "cmdStopScan"
        Me.cmdStopScan.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdStopScan.Size = New System.Drawing.Size(93, 29)
        Me.cmdStopScan.TabIndex = 5
        Me.cmdStopScan.Text = "停止扫描"
        '
        'List1
        '
        Me.List1.BackColor = System.Drawing.SystemColors.Control
        Me.List1.Cursor = System.Windows.Forms.Cursors.Default
        Me.List1.ForeColor = System.Drawing.Color.Black
        Me.List1.ItemHeight = 12
        Me.List1.Location = New System.Drawing.Point(16, 72)
        Me.List1.Name = "List1"
        Me.List1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.List1.Size = New System.Drawing.Size(384, 196)
        Me.List1.TabIndex = 1
        '
        'cmdStartScan
        '
        Me.cmdStartScan.BackColor = System.Drawing.SystemColors.Control
        Me.cmdStartScan.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdStartScan.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdStartScan.Location = New System.Drawing.Point(48, 288)
        Me.cmdStartScan.Name = "cmdStartScan"
        Me.cmdStartScan.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdStartScan.Size = New System.Drawing.Size(93, 29)
        Me.cmdStartScan.TabIndex = 0
        Me.cmdStartScan.Text = "开始扫描"
        '
        'Winsock1
        '
        Me.Winsock1.Enabled = True
        Me.Winsock1.Location = New System.Drawing.Point(829, 19)
        Me.Winsock1.Name = "Winsock1"
        Me.Winsock1.OcxState = CType(resources.GetObject("Winsock1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.Winsock1.Size = New System.Drawing.Size(28, 28)
        Me.Winsock1.TabIndex = 14
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.SystemColors.Control
        Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label3.ForeColor = System.Drawing.Color.Black
        Me.Label3.Location = New System.Drawing.Point(280, 16)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(93, 19)
        Me.Label3.TabIndex = 9
        Me.Label3.Text = "结束端口"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.ForeColor = System.Drawing.Color.Black
        Me.Label2.Location = New System.Drawing.Point(152, 16)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(94, 19)
        Me.Label2.TabIndex = 8
        Me.Label2.Text = "开始扫描"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.Control
        Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label1.ForeColor = System.Drawing.Color.Black
        Me.Label1.Location = New System.Drawing.Point(8, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(48, 19)
        Me.Label1.TabIndex = 7
        Me.Label1.Text = "IP地址"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.Menu
        Me.ClientSize = New System.Drawing.Size(416, 333)
        Me.Controls.Add(Me.cmdExit)
        Me.Controls.Add(Me.cmdStopScan)
        Me.Controls.Add(Me.txtEndingPort)
        Me.Controls.Add(Me.txtStartingPort)
        Me.Controls.Add(Me.txtIP)
        Me.Controls.Add(Me.List1)
        Me.Controls.Add(Me.cmdStartScan)
        Me.Controls.Add(Me.Winsock1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Location = New System.Drawing.Point(11, 30)
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "扫描计算机端口"
        CType(Me.Winsock1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
#End Region

    Dim pstrIp As String
    Dim msngPort As Single
    Dim msngEndingPort As Single
    Dim msngStop As Single
    Dim x As Single
    Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
        Dim pstrmessage As String
        pstrmessage = CStr(MsgBox("确认退出?", MsgBoxStyle.YesNo))
        If pstrmessage = CStr(MsgBoxResult.Yes) Then
            End
        End If
    End Sub
    Private Sub CmdStartScan_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdStartScan.Click
        msngPort = Val(txtStartingPort.Text)
        msngEndingPort = Val(txtEndingPort.Text)
        msngStop = 0
        List1.Items.Clear()
        List1.Items.Add(("         ************** 端口扫描 **************"))
        tedlock()
        Dim msngTotalPorts As Single

        Do Until msngPort = msngEndingPort
            msngTotalPorts = msngTotalPorts + 1

            If msngStop = 1 Then
                Exit Sub
            End If


            For x = 1 To 1500000
            Next

            System.Windows.Forms.Application.DoEvents()
            pstrIp = txtIP.Text
            System.Windows.Forms.Application.DoEvents()
            Winsock1.Close()
            Winsock1.Connect(pstrIp, msngPort)


            For x = 1 To 1500000
            Next

            msngPort = msngPort + 1
            txtEndingPort.Text = CStr(msngPort)


            For x = 1 To 1500000
            Next

            System.Windows.Forms.Application.DoEvents()

            If msngPort = msngEndingPort Then
                UnlockControls()
                List1.Items.Add((" "))
                List1.Items.Add((" "))
                List1.Items.Add(("完成扫描 " & msngTotalPorts & " Ports" & " !!"))
            End If

        Loop
    End Sub

    Private Sub cmdStopScan_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdStopScan.Click
        UnlockControls()
        msngStop = 1
        List1.Items.Add((" "))
        List1.Items.Add((" "))
        List1.Items.Add(("扫描停止!"))
    End Sub

    Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        txtIP.Text = Winsock1.LocalIP
        txtStartingPort.Text = CStr(1)
        txtEndingPort.Text = CStr(65530)
        List1.Items.Add(("         ************** 端口扫描 **************"))
        UnlockControls()
    End Sub

    '判断端口是否有连接,如果有就添加到列表框中
    Private Sub Winsock1_ConnectEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Winsock1.ConnectEvent
        List1.Items.Add(("Port " & Winsock1.RemotePort & " Connected"))
    End Sub
    '当扫描进行的时候
    Private Sub tedlock()
        cmdExit.Enabled = False
        cmdStartScan.Enabled = False

        cmdStopScan.Enabled = True
        txtIP.ReadOnly = True
        txtStartingPort.ReadOnly = True
        txtEndingPort.ReadOnly = True
    End Sub

    '当扫描完成或停止时
    Private Sub UnlockControls()
        cmdExit.Enabled = True
        cmdStartScan.Enabled = True
        cmdStopScan.Enabled = False
        txtIP.ReadOnly = False
        txtStartingPort.ReadOnly = False
        txtEndingPort.ReadOnly = False
    End Sub


End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -