Author: Lord Nikon
December 8, 2005
To make the port scanner, start of by making a standard EXE. Press CTRL+T, choose Microsoft Winsock Control 6.0 from the list.
Add some controls to your program so it looks like this:

In the Start Timer's timer event add this code:
Private Sub Timer1_Timer()
On Error Resume Next
Winsock1.Close
txtPort.Text = Int(txtPort.Text) + 1
Winsock1.RemoteHost = txtHost.Text
Winsock1.RemotePort = txtPort.Text
lblPort.Caption = Winsock1.RemotePort
Winsock1.Connect
End Sub
What this does is that it specifies our Winsock's remote host and remote port as the text boxes we creates. txtPort.Text = Int(txtPort.Text) + 1 simply means that we want the port number to increase by 1 each time a port is scanned. Then we display the Host's port in the label lblPort.
In the Start button add this code:
Private Sub cmdStart_Click()
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
This sets the timer's interval to 1 millisecond, and enables the timer so all the code in the timer is executed in a loop.
In the Stop button add this code:
Private Sub cmdStop_Click()
Timer1.Enabled = False
txtPort.Text = "0"
End Sub
This code disables timer1 so the loop is broken and resets the info.
In Winsock's Connect event add this code:
Private Sub Winsock1_Connect()
lstLog.AddItem (Winsock1.RemotePort & " is open")
End Sub
This just lists each open port to the list box everytime Winsock successfully connects to an open port.
In the formload event add this code:
Private Sub Form_Load()
txtHost.Text = Winsock1.LocalIP
txtPort.Text = Winsock1.LocalPort
End Sub
This places the computer's IP in the IP text box and the port in the port text box.
And finally in the form UNload event add this code:
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
This is just to make sure the processes or our program doesn't keep running after the user had closed the program.
Run the program and if you did everything right you should get results like this:

Download: Sample Program
|