Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27

Thread: Creating a Port Scanner in Visual Basic

  1. #11
    Originally posted here by TheSpecialist
    No no no no... not at all. Mostly everything I make & post up here is done as a joke. The last time I made a port scanner in VB & posted it here I claimed "source commenting is for retards" shortly before one of the first things peaple responded and complained about was the lack of commenting and readability of the code.

    If im not mistaken I beleave I also re-named a few variables & things as comic book characters, if you can actually read through it you'll also notice one's value is incorrect and I did it all just for shits and giggles. I dunno basicly just to see who would say something about it as opposed to who would mindlessly thank me for it one way or the other.

    Ummm... I thought it was kinda funny & others didn't. I guess you had to have been there and seen it.


    As a joke? The only thing funny about the port scanner you "wrote", and I use the term loosely here, was the fact that you posted it in a public forum. It was truly bad. From the James Bond / cartoon interface, to the superhero naming convention, to the myriad of nested loops, to the default names of form elements ... It gave me diarrhea.

  2. #12
    Senior Member
    Join Date
    Feb 2004
    Posts
    620
    Originally posted here by Falcon21
    Hello, I am a beginner in VB. I have some questions: why is there a need for number of max connections and how many should one put? What if I put 1 max connection and it can't connect to a port, then the "sckScan_Connect(Index As Integer)" event procedure will not be executed? Then how it will scan the next port?

    Is it better to declare the Index variable in Sub "TryNext(Index)" to "TryNext(Index as integer)"?

    Btw, I haven't check out your attachment.
    The reason I have max connections is so it can scan faster. The higher the number you put in there, the more connections it will make at the same time. Don't put too high of a number though, or it will actually make it slower.

    Thanks for the replies and the criticism I realise this wasn't the best-written code.. but it is a good example for beginners to learn about Winsock and arrays of controls. Thanks again.

    mjk

    EDIT:
    Is it better to declare the Index variable in Sub "TryNext(Index)" to "TryNext(Index as integer)"?
    Oops! That would be the correct way to do it... Not sure what I was thinking

  3. #13
    Senior Member Falcon21's Avatar
    Join Date
    Dec 2002
    Location
    Singapore
    Posts
    252
    I placed 100 max connections and found a bug. The scanner show a open port 3 times! For example I got this:
    Port 1043
    Port 1043
    Port 1043
    If I place 1 max connection it will display the open port 3 times. I tried to place a label as a counter to the Form to display the current port being scanned but I got a strange result - The current port being scanned is at around a few hundreds but it already show port 1043 as open! I just can't figure out how to solve this.

    Anyway, here is a good way to allow only number to be input into the textbox for the port:

    Private Sub TextBox_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case 8, 48 To 57 '8 is backspace, 48 to 57 is 0 to 9
    Case Else
    KeyAscii = 0
    End Select
    End Sub

    There must also be some checks to make sure the starting port is less than and not equal to the ending port, starting port must be more than 0 and less than 65535 and this also goes to the ending port.
    Another thing is that if I put 100 max connections and the port range is less than 100 ports, then the scanner will scan beyond the port range!

  4. #14
    Senior Member Falcon21's Avatar
    Join Date
    Dec 2002
    Location
    Singapore
    Posts
    252
    Does anyone know how to create a VB scanner to check for UDP open ports?

  5. #15
    Originally posted here by Falcon21
    Does anyone know how to create a VB scanner to check for UDP open ports?
    Same as you would a TCP/IP port scanner. The only difference is that you would set the winsock object Protocol property, to sckUDP, instead of sckTCP.

  6. #16
    Senior Member
    Join Date
    Feb 2004
    Posts
    620
    Originally posted here by Falcon21
    I placed 100 max connections and found a bug. The scanner show a open port 3 times! For example I got this:
    Port 1043
    Port 1043
    Port 1043
    If I place 1 max connection it will display the open port 3 times.

    Hmm.. I don't get that when I put in 1 for max connections. It gives each port once. What port range did you enter?

    Anyway, here is a good way to allow only number to be input into the textbox for the port:

    Private Sub TextBox_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case 8, 48 To 57 '8 is backspace, 48 to 57 is 0 to 9
    Case Else
    KeyAscii = 0
    End Select
    End Sub

    There must also be some checks to make sure the starting port is less than and not equal to the ending port, starting port must be more than 0 and less than 65535 and this also goes to the ending port.
    Another thing is that if I put 100 max connections and the port range is less than 100 ports, then the scanner will scan beyond the port range!
    I have inserted that code you have for KeyPress. Also I made some checks for the port range.

    I CANNOT for the life of me figure out how to fix the problem of it scanning beyond the range. The code looks like it should work but for some reason it always scans beyond if you put too many max connections. I've tried a bunch of different ways but no luck... Anyone see what's going on?

    Does anyone know how to create a VB scanner to check for UDP open ports?
    You should be able to just change the Protocol property of a Winsock control to sckUDPProtocol. I haven't tried it though.

    mjk

    EDIT:
    I figured out a simple way to fix it. Well it doesn't really fix it but... When you click "Scan" it checks how many ports it will scan, then compares the number to the Max Connections text box. If max connections is more, it aborts and returns an error message.

    I'm about to update the attachment with the changes I've made. Download it and check out the improved version.

  7. #17
    Senior Member
    Join Date
    Feb 2004
    Posts
    620
    Ok new version successfully uploaded. If you find any more bugs (very probable) please tell me

    mjk

  8. #18
    Originally posted here by SexyBadGirl
    Same as you would a TCP/IP port scanner. The only difference is that you would set the winsock object Protocol property, to sckUDP, instead of sckTCP.
    No that won't work. You know its funny, you'd figure for a guy who likes repeateing what I've already said about what I have done and generally stateing the obvious... he'd atleast know whats wrong with his recent statement.

  9. #19
    Senior Member Falcon21's Avatar
    Join Date
    Dec 2002
    Location
    Singapore
    Posts
    252
    Originally posted here by mjk
    Hmm.. I don't get that when I put in 1 for max connections. It gives each port once. What port range did you enter?
    I have 100 max connections and port range from 1 to 65535. Make sure you have one listening port to test for. It just print out the open port 3 times...

    Btw, why can't port 0 be scanned?

  10. #20
    Because its reserved.
    http://grc.com/port_0.htm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •