Coder Profile - Show off your skills, get a coder profile.
 
 
 
Basic PortScanner in VB6.0
Programming
Basic Port Scanner in VB6.0



What is a Port Scanner?

- A port scanner is a simple program that scans a computer for open ports. The one we are going to make uses TCP. It uses the three way handshake to look for open ports.
You can compare it to a thief going on his "scout-tour". e goes to a house before he breaks in and checks every door and window to see if anything is open so he can enter later that night without forcing something.

Why would I need one?

-A port scanner can serve many purposes, you can check to see if you are infected with a certain Trojan by checking your computer's open ports for specific Trojan ports. Or it can be used to see if a victim has any vulnerable ports open that can be used to gain further access to the machine.

How can I create one with visual basic 6.0?

- First we need to add the winsock control to our tool box so create a new project and go to the components screen (ctrl+t) then check the box next to Microsoft winsock control 6.0, and press ok. After that the control should be added to your toolbar on the left, just drag one to your form.

Now create 2 textboxes, 2 buttons, 1 timer and 1 listbox.
The first textbox is for the ip's, the second is for the starting port, the first button is for starting the scan, the second one is to stop the scanning. Then go to the timer and in the properties on the right change enabled to false and interval to 1000.
If you like to fancy up your form with some warm colors and a fluffy border be my guest.

Next go to the code window and type in the following.
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. Private Sub Command1_Click()
  2.        Winsock1.RemoteHost = Text1.Text ' The ip address or url to connect to
  3.        Winsock1.RemotePort = Text2.Text ' The first port
  4.        Winsock1.Connect
  5.  
  6.        Timer1.Enabled = True ' the rest of the ports.
  7. End Sub
  8.  
  9. Private Sub Timer1_Timer()
  10.        ' closes the last connection
  11.        Winsock1.Close
  12.  
  13.        'increases the port by one
  14.        Text2.Text = Int(Text2.Text) + 1
  15.  
  16.        Winsock1.RemoteHost = Text1.Text
  17.        Winsock1.RemotePort = Text2.Text
  18.        Winsock1.Connect
  19. End Sub
Now maybe you are wondering why I connected once an then enabled the timer to connect for the rest, well because of the line " Text2.Text = Int(Text2.Text) + 1 'increases the port by one " it doesn't scan the first port so you have to do it yourself .
Now we have the scanning core of the port scanner, now we need something that says when it's open and when not.
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. Private Sub Winsock1_Connect()
  2.        List1.AddItem "Port " & Winsock1.RemotePort & " Is Open"
  3. End Sub
This is why winsock is easy to use, everything you need is build in a nice sub. So we just code the connect sub so that when it is called by the winsock scanning for ports it puts the port number in the list.

So that's basically it, but to make it complete we will code the stop button now,
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. Private Sub Command2_Click()
  2.        Timer1.Enabled = False ' stops the scanning timer
  3.        Winsock1.Close ' closes any open winsock connection that was still open.
  4. End Sub
That is it, you now have a simple working port scanner.

Things you could do to make it better:
- make a case statement in the winsock1.connect sub to recognize special ports.
- make it multi threading so several sockets work with each other to scan faster.
- make it output the scan result to a text file
- etc

Disclaimer

I am not responsible for any thing you might do with this, This is for educational purposes only.

If you find any errors please PM me and I will be sure to make corrections.
~ShadyTyrant~


Posted By shadytyrant
Please login to rate coding articles.

Click here to register a free account with us.
Attached Image
Comments
Please login to post comments.
Page 1 of 1
More Articles By This Author
Selecting Your First Programming Language
Basic PortScanner in VB6.0
Recently Posted "Programming" Articles
thetrojan01's brainfuck tutorial - from the beginning to the interpreter.
My Experiences So Far with Languages
Selecting Your First Programming Language
[PHP] - Lets kill the complex IF
Basic PortScanner in VB6.0
N-Queens-Series Part I (Only the fittest survive)
Currying in JavaScript: Fun for the Whole Family!
[PHP] Create A Unique Page Hits Counter
Actionscript Events
Actionscript API
Recently Rated "Programming" Articles
thetrojan01's brainfuck tutorial - from the beginning to the interpreter.
[PHP] - Lets kill the complex IF
Actionscript API
Actionscript Events
My Experiences So Far with Languages
Selecting Your First Programming Language
Vectors in C++
[C++] Templates
Quick Threading Tutorial - C++
Intorduction to memoization.
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (1)
Hardware (1)
Internet & Web Sites (3)
Life In General (2)
Networking (1)
Operating Systems (4)
Other (2)
Programming (46)
Security (8)
Software Development (5)
Web Development (14)
search Search Inside
Programming
 
 
Latest News About Coder Profile
Coder Profile Poll
Which sounds better on your coder profiles, and makes more sense to you (think twitter, facebook, etc)?

Followers / Following
Fans / Following
Fans / Fan Of


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.20 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved