Results 1 to 34 of 34

Thread: Is this port open or blocked ??[Resolved]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Is this port open or blocked ??[Resolved]

    How can I check if a speific port is open or blocked ? Don't tell me check Socket or web classes plz

    Thanks
    Last edited by Pirate; Sep 18th, 2003 at 05:07 PM.

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Through code? There are also port scanner utilities, I use "Advanced Port Scanner", but there's a bunch of free/shareware.

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I know there are a lot of utilities but I need some code for some reason which is part of big proj I'm working on .... . Any ideas ?

    thanks

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Why wouldn't you try with a socket? Seems easy enough.

  5. #5

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Umm , I checked it and couldn't do anything or I'm not sure it would solve the problem so , Anyone ?

  6. #6
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    lol
    just try to host in the specified port and if u get an "port already in use" exception then it's being used......
    \m/\m/

  7. #7

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Can you show me how because I've never used this class before ?

    Thnanks .

  8. #8
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i really never done that before but tonight when i get home i can see if i can do that..it can't be too hard
    \m/\m/

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. Dim tr As System.Net.Sockets.TcpListener = New System.Net.Sockets.TcpListener(8000) 'change 8000 to whatever port
    2.         Try
    3.             tr.Start()
    4.         Catch ex As Exception
    5.             System.Windows.Forms.MessageBox.Show(ex.ToString)
    6.         End Try

  10. #10

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    nemaroller , first shows blue line under 'tr' declaration , though it run with no errors . After running this code , nothing happens , after clicking 1 more time , it shows this error :

    System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
    at System.Net.Sockets.Socket.Bind(EndPoint localEP)
    at System.Net.Sockets.TcpListener.Start()

    What's the problem ?

  11. #11
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
    at System.Net.Sockets.Socket.Bind(EndPoint localEP)
    at System.Net.Sockets.TcpListener.Start()

    What's the problem ?
    it's throwing an error because the port is in use , which is how nemaroller meant it to work ( if you get the error message, then you know the port is in use )
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  12. #12

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    No , you don't get it yet. If the port is being used and I clicked the buttton , it should throw the error right away not after the second click or the third . This doesn't seem to be reliable way . I need some API stuff if possible .

    Thanks

  13. #13

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I tried these port numbers (1,80,81,21,8000,60000,1234) . Same error after two clicks nothing happens after 1 click !

  14. #14
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    It's late and i am going home so forgive me if i am being thick-

    BUT:

    The first click claims the port the second is denied and an exception is generated - isn't that what your after?

    Cheers...

  15. #15

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by powdir
    It's late and i am going home so forgive me if i am being thick-
    BUT:
    The first click claims the port the second is denied and an exception is generated - isn't that what your after?
    Cheers...
    This error applies to all the port number I tried with . I assume port number (60000 or something like this) would be free since I've never seen an app uses this number and also larg values ranging from 2000 to 65xxx . I don't know if this make sense but....it doesn't solve the problem yet .

  16. #16
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    sorry to say but it DOES really work..u said u tried with port 21 but do u have an ftp server?!
    \m/\m/

  17. #17

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by PT Exorcist
    sorry to say but it DOES really work..u said u tried with port 21 but do u have an ftp server?!
    lol , no but I was connecting to an ftp site . Did you test it to say it works ?

  18. #18
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    OMG

    Dim tr As System.Net.Sockets.TcpListener = New System.Net.Sockets.TcpListener(21) 'change 8000 to whatever port

    look at it

    tcpLISTENER

    this is HOSTING in your computer

    this is to see if u have in YOUR computer any port open

    i think u didnt quite explain what u wanted..u want to check in OTHER computer right?

    sorry if i am being too agressive i have an headache..sorry
    \m/\m/

  19. #19

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    No , I want to detect if specific port number is open or blocked . That's all about . Again , I tested the code but it doesn't work for me at least . I don't if it's me or the code or the port .

  20. #20
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    anyways here's the code

    Code:
            Try
                Dim ts As System.Net.Sockets.TcpClient = New System.Net.Sockets.TcpClient("127.0.0.1", 654)
            Catch ex As System.Net.Sockets.SocketException
                If (ex.ErrorCode = 10061) Then
                    MsgBox("The port isnt being used in the target machine")
                End If
            End Try
    \m/\m/

  21. #21
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Originally posted by Pirate
    No , I want to detect if specific port number is open or blocked . That's all about . Again , I tested the code but it doesn't work for me at least . I don't if it's me or the code or the port .
    but you want to check it in your computer or in a remote computer?
    \m/\m/

  22. #22

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    In my computer . ...

  23. #23

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I think it just programmed to say ""The port isnt being used in the target machine" . I couldn't find any open port . I have norton antivirus but I don't think it's able to close all port and I can't believe all these ports are being used by any resource or program (0 through 65525 or so)

  24. #24
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    using the other guy's code will check if in YOUR computer there is any port being used and yes it works, i tried with several ports and it did work.

    my code checks in ANY computer(it can be remote or not) if a port is open(at least it tries to connect and if u get 10061 error code that means the computer machine refused the connection it will show the msg), then again i tried with several ports and it worked very well in all the ports

    \m/\m/

  25. #25

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by PT Exorcist
    using the other guy's code will check if in YOUR computer there is any port being used and yes it works, i tried with several ports and it did work.

    my code checks in ANY computer(it can be remote or not) if a port is open(at least it tries to connect and if u get 10061 error code that means the computer machine refused the connection it will show the msg), then again i tried with several ports and it worked very well in all the ports

    What ports did you try ? and did you use the loopback ip or you internet IP ? for me it shows all ports I've tried are in use .

  26. #26

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I used my internet IP and still same msg . Something is missing I think .

  27. #27

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Actually , the error message confused me . I downloaded a tool that checks first for port opened and then I try them in my code . I found only 5 ports open and others are closed but I don't believe this . Maybe a lot of them are not configured not closed or something like this...lol

    anyway it's sorted out . This code work .
    VB Code:
    1. Try
    2.             Dim ts As System.Net.Sockets.TcpClient = New System.Net.Sockets.TcpClient("127.0.0.1", 654)
    3.         Catch ex As System.Net.Sockets.SocketException
    4.             If (ex.ErrorCode = 10061) Then
    5.                 MsgBox("The port [SIZE=3]is[/SIZE]  being used in the target machine")
    6.             End If
    7.         End Try

    Thanks everyone for the time .

  28. #28
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    glad to see my code worked

    \m/\m/

  29. #29
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Originally posted by Pirate
    No , you don't get it yet. If the port is being used and I clicked the buttton , it should throw the error right away not after the second click or the third . This doesn't seem to be reliable way . I need some API stuff if possible .

    Thanks
    It doesn't error on the first click, because that port was not in use, and my code opened a port on it. The second time around, its in use, so then it errors.

    If it doesn't error on the first click, then that port is available. I guess I should have mentioned you would want to close that port (tr.Close or tr.Stop don't remember which).

  30. #30

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    A question just came to my mind , How does it listen to the port ? I mean , does the port need to be opend to listen to ?

  31. #31
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Originally posted by Pirate
    A question just came to my mind , How does it listen to the port ? I mean , does the port need to be opend to listen to ?
    of course
    otherwise any program would read other program's port and could do anything he wanted to
    \m/\m/

  32. #32

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    ah cool . thx

  33. #33
    New Member
    Join Date
    Sep 2007
    Posts
    1

    Re: Is this port open or blocked ??[Resolved]

    Hi everybody !!! This blog has been real helpful. I dont know if the thread is still alive. I might not get a reply back . Still giving it a try.

    I am trying to do what "Pirate" was trying to do. The difference is, I am trying to Detect local as well as Remote PC's ports. I am trying to detect if the port (say 4000) is unblocked on the Local as well as a Remote PC. Please mind it, I am looking for bloceked/unblocked status and not open/close. Open means its in use and close means its not in use(But can be unblocked at the same time), because no service is being used on that port.

    I could do Local machine port detection very well with the below mentioned code:
    This works absolutely perfect guys. I installed a firewall on my local machine and tested the code. Perfect !!!
    -----------------------------------------
    by: nemaroller


    Dim tr As System.Net.Sockets.TcpListener = New System.Net.Sockets.TcpListener(8000) 'change 8000 to whatever port
    Try
    tr.Start()
    Catch ex As Exception
    System.Windows.Forms.MessageBox.Show(ex.ToString)
    End Try
    --------------------------

    The trouble is detecting the ports on Remote Computer

    I tried using the code by PT Exorcist

    --------------

    Try
    Dim ts As System.Net.Sockets.TcpClient = New System.Net.Sockets.TcpClient("127.0.0.1", 654)
    Catch ex As System.Net.Sockets.SocketException
    If (ex.ErrorCode = 10061) Then
    MsgBox("The port isnt being used in the target machine")
    End If
    End Try
    ---------------

    But it doesnt seem to work.

    I am in a LAN connected over Switch and connected through a Router(Gateway) to the internet.

    I tried to check a port on a remote machine, but without sending an access request to the remote machine, I said "The port isnt being used in the target machine"..

    The code might be fine. am doing a little research on it. .

    Still if you guys have any suggestion, I would really appreciate that.

    I need a code for Checking if a port is blocked on Remote PC. (blocked/unblocked)

    I am implementing the whole thing in C#. so C# or VB .Net would do ..

    Thanks everybody,
    Regards,

  34. #34
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Is this port open or blocked ??[Resolved]

    Please dont push others thread.Create ur Own Thread.Normaly u wont get replies for a thread which is marked as resolved
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

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



Click Here to Expand Forum to Full Width