Post: [TUT] ---> Port Scanner <--- [VB.NET]
05-10-2011, 12:01 AM #1
(adsbygoogle = window.adsbygoogle || []).push({});
Originally posted by kingdeath360 View Post
Note: I take no credit for the coding of this port scanner..
Credits go to David Kramer for posting it on You must login or register to view this content.[/color]

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:'

Your end result should look something like this:

You must login or register to view this content.

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)
Try
s.Connect(EPhost)
Catch
End Try
If Not s.Connected Then
ListBox1.Items.Add("Port " + port.ToString + " is not open")
Else
ListBox1.Items.Add("Port " + port.ToString + " is open")
ListBox2.Items.Add(port.ToString)
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)
ListBox1.Items.Add("-------------------")
Button2.Enabled = True
Button1.Enabled = False
Timer1.Enabled = True
Timer1.Start()
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.Stop()
Timer1.Enabled = False
Button1.Enabled = True
Button2.Enabled = False
End Sub



This is my first VB.NET Tutorial so be nice...
Enjoy...

source You must login or register to view this content.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo