Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27389

creating a delay while open port numbers are being returned to the screen

$
0
0
Hi guys,
I'm building a port scanner in visual basic. I enter the address if the address I wish to scan I.E. www.google.com, then I enter the port numbers I wish to check.
The ports can be scanned individually or a group of ports can be scanned to check weather they are open or not I.E. 80, 23, 431.
What I'm trying to do is create a delay. So it I check 6 ports in one scan the port weather it be open or closed appear on screen one by one as opposed to all appearing all together.
Any help would be greatly appreciated, thanks.
Code:

Imports System
Imports System.Net
Imports System.Net.Sockets

Public Class Form1


    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()

    End Sub


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Cursor = Cursors.WaitCursor

        Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        Dim ipHostInfo As IPHostEntry = Dns.Resolve(TextBox1.Text)
        Dim portnum As Integer
        Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
        Dim i As Integer
        'MessageBox.Show(ipAddress.ToString)                'Shows ip address in message box
        Label3.Text = ipAddress.ToString

        If (ComboBox1.Text = "All") Then
            For i = 1 To ComboBox1.Items.Count - 1
                portnum = CInt(ComboBox1.Items(i))
                'start connection attempt

                Dim ipe As New IPEndPoint(ipAddress, portnum)

                Try
                    s.Connect(ipe)
                    If s.Connected Then
                        'MessageBox.Show("Got There" & portnum)
                        TextBox2.Text = TextBox2.Text & vbCrLf & "Attempting connection on port " & portnum & "...success"
                    End If
                Catch se As SocketException
                    'MessageBox.Show("Nothing Happening on port " & portnum)
                    TextBox2.Text = TextBox2.Text & vbCrLf & "Attempting connection on port " & portnum & "...failure"
                    '& "..... failure" & vbCrLf
                End Try

                Me.Cursor = Cursors.Default
                'end conection attempt
            Next
        Else
            portnum = CInt(ComboBox1.Text)
            'start connection attempt
            Dim ipe As New IPEndPoint(ipAddress, portnum)
            Try
                s.Connect(ipe)
                If s.Connected Then
                    'MessageBox.Show("Got there on port " & portnum)
                    TextBox2.Text = TextBox2.Text & vbCrLf & "Attempting connection on port " & portnum & "... success"
                End If
            Catch se As SocketException
                'MessageBox.Show("Nothing Happening on port " & portnum)
                TextBox2.Text = TextBox2.Text & vbCrLf & "Attempting connection on port " & portnum & "...failure"
            End Try

            Me.Cursor = Cursors.Default
            'end conection attempt
        End If

    End Sub
End Class


Viewing all articles
Browse latest Browse all 27389

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>