Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB.NET Port Scanner [TUT]
Note: I take no credit for the coding of this port scanner..
Credits go to David Kramer for posting it on Code Project

Ok so first off create a new Windows Application Form
You will need to add:

- TextBox X2
- ListBox X2
- Button X2
- Labels
- Timer

Add a label next to TextBox1 saying 'Host:'
And add 1 next to TextBox2 saying 'Port:'
Change the text on Button1 to 'start'
Change Button2 to 'stop'
Add a label for ListBox1 saying 'Ports being scanned:'
Add 1 for ListBox2 saying 'Open ports:'


Ok now for the coding...

First off declare the variables

Dim host As String
Dim port As Integer
Dim counter As Integer

Add the following to Form_load

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button2.Enabled = False
        TextBox2.Text = "0"
        'set counter explained before to 0
        counter = 0
    End Sub

Add the following to Timer_tick

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
      'Set the host and port and counter
        counter = counter + 1 'counter is for the timer
        TextBox2.Text = counter
        host = TextBox1.Text
        port = TextBox2.Text
        ' Next part creates a socket to try and connect on with the given user information.
        Dim hostadd As System.Net.IPAddress = System.Net.Dns.GetHostEntry(host).AddressList(0)
        Dim EPhost As New System.Net.IPEndPoint(hostadd, port)
        Dim s As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, _
        System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
        End Try
        If Not s.Connected Then
            ListBox1.Items.Add("Port " + port.ToString + " is not open")
            ListBox1.Items.Add("Port " + port.ToString + " is open")
        End If
        Label3.Text = "Open Ports: " + ListBox2.Items.Count.ToString
    End Sub

Add the following to the Start button_click

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Add("Scanning: " + TextBox1.Text)
        Button2.Enabled = True
        Button1.Enabled = False
        Timer1.Enabled = True
    End Sub

Add the following to Button2_click (stop)

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'stop button
        Timer1.Enabled = False
        Button1.Enabled = True
        Button2.Enabled = False
    End Sub

Hope this helps. Blackhat
Bump... Nobody find this useful? lol Sad
thanks For Sharing Major

Big Grin


Plz contact me in MSN
If you are willing to join SF Webmasters.
Ok i managed to get as far building with no errors.
When i run the application, if put ip into host i get a constant unexpected error warning.
When i put a domain name, it works if left alone, but ignores the port number i put in port and just starts from port 1 and continues to check even past
the port i put.
And if i try and stop it, it stops responding and i have to end the program.

Im new to this. So maybe i have other looked something.
Please help
[Image: s1.jpg]
Very nice tut dude..

[Image: 20r9vh4.jpg]
@Phire, I don't know what you mean. Can you maybe post a screenshot?
It work, thanks.
Very nice TUT "The Major" keep up the Good Work.
[Image: OGForumsbanner.png]
No worries. I'm glad you all like it.
Great tutorial, I've used your tutorial once and it worked. Thank you.

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to hook the keyboard. [VB.NET] [TuT] Vorfin 124 33,099 09-23-2019, 11:55 AM
Last Post: Jamimartin
  Free Advanced Port Scanner SOURCE [ VB.NET ] Filefinder 6 3,185 01-22-2013, 04:27 AM
Last Post: TalishHF
  [TUT] MD5 Encrypter & Finder [VB.NET] Fragma 12 4,490 11-25-2012, 10:36 PM
Last Post: ƃu∀ ıʞƃu∀
  [TUT] How to make a simple WebBrowser in VB 2010! [TUT] - [ Pictures] Statics 95 35,919 10-07-2012, 06:56 AM
Last Post: a99
  [TUT]Enable and Disable TaskManger in [TUT] HB Virus 4 1,529 12-19-2011, 10:10 AM
Last Post: euverve

Forum Jump:

Users browsing this thread: 1 Guest(s)