dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Find an open port

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    295

    Resolved [RESOLVED] Find an open port

    Hello all,

    I have written a small utility (see my sig) to scan for open ports on a connected router. Nothing nefarious.

    The code works fine, only it takes a long time to scan each of the 65K ports.
    is there an easier way to accomplish this? Also, is there a more accurate way? I compare my results to the open source Nmap and they always find at lease one extra open port and they take 1/2 the time I do.

    Thanks,

    -NJ

    Here is my code...


    BGWNum = Port number

    Code:
            Try
    
                Dim myTcpClient As New TcpClient()
                Try
                    myTcpClient.Connect(RouterIP, BGWNum)
    
                    If myTcpClient.Connected Then
                        worker.ReportProgress(BGWNum, "Open")
                        myTcpClient.Close()
                    End If
                Catch sex As SocketException
                Catch ex As Exception
    
                End Try
    
            Catch ex As Exception
                ErrorLogReturnCode = WriteError.WriteToErrorLog("(ScanRouterForOpenPorts) TCPClient Detect : " & ex.Message)
            End Try
    Lo And Behold
    This is my first Microsoft App Submission
    Your opinion of it would be appreciated

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,569

    Re: Find an open port

    Try/Catch exception handling is a little more intensive than other methods, but generally this is a good thing. You could specify a timeout period, but if you set the timeout period too short then you could incorrectly state that a port is closed when it is actually opened. I tested it on my end and it takes several minutes for it to completely scan all 65,535 ports. This is probably just a situation where VB.NET is not the most efficient tool, after all Nmap is basically written in C.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    295

    Re: Find an open port

    Quote Originally Posted by dday9 View Post
    Try/Catch exception handling is a little more intensive than other methods, but generally this is a good thing. You could specify a timeout period, but if you set the timeout period too short then you could incorrectly state that a port is closed when it is actually opened. I tested it on my end and it takes several minutes for it to completely scan all 65,535 ports. This is probably just a situation where VB.NET is not the most efficient tool, after all Nmap is basically written in C.
    I was afraid of that.
    Thank you for the reply!
    Lo And Behold
    This is my first Microsoft App Submission
    Your opinion of it would be appreciated

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width