Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 41

Thread: Checking a port if it's in use/open

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking a port if it's in use/open

    Quote Originally Posted by prof.ebral View Post
    I also like having the option of being able to code my own firewall.
    But do it with means meant for coding a firewall, not a userspace application.

    The OP can thread the connections and when a connetion attempt is made to a port he can be notified, release the port, and allow the connection to proceed.
    Hmm? Could you share a snippet of that does what you mean? Where would the connection proceed exactly? It seems you are using unix, so let's assume netcat started as
    bash Code:
    1. netcat -l 10001
    To copy to clipboard, switch view to plain text mode 
    ... to be our server. Please write a minimal application (using whatever technology available for a standard u*ix system) that will bind a userspace application to tcp port 10001, intercept the connection, issue some debugging statement to the console and let the connection be picked up by the netcat pseudo-server.

    Please also perform a (shallow) theoretical analysis of how the tcp handshake (SYN ->, SYN+ACK <-, ACK ->)would look like from the client's perspective in such a situation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #22
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Checking a port if it's in use/open

    Quote Originally Posted by prof.ebral View Post
    I don't agree with this totally, fatjuicymole. The OP can thread the connections and when a connetion attempt is made to a port he can be notified, release the port, and allow the connection to proceed.
    Explain how to do this with Qt. I don't think it's possible for the simple reason that a user-level application doesn't have that kind of access (and Qt only works in user-land). Sure, you can get the connect notification and ignore it (not accept the connection request), but you then can't pass on that notification to some other program without affecting the source route. The only way I see it working is if the client automatically has multiple retries, so the notification app gets the first, releases the port, and VNC gets the next, but thats hardly a practical solution.

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking a port if it's in use/open

    Quote Originally Posted by fatjuicymole View Post
    The only way I see it working is if the client automatically has multiple retries, so the notification app gets the first, releases the port, and VNC gets the next, but thats hardly a practical solution.
    IMO this wouldn't work too, because of at least these facts and situations:

    1. smart network stacks (or maybe it's even enforced by the standard, I don't remember) disallow binding to a just-released port to prevent stale connections/stray packets that might confuse the new daemon
    2. race condition between the client and "server-switching" after an incoming connection is detected
    3. a situation when the server can handle more than one connection simoultaneously - you wouldn't get any notification about new connections when there would already be a connection accepted by the real server
    4. detecting when to reinstate the "peeking" daemon once the true connection is closed (+ a race condition again)

    Of course I know how to do it in some special conditions in userland using Qt, i.e. on Linux you can implement a netlink device that will receive all incoming SYN packets before they are delivered to their destination but this is part of Linux firewalling mechanism, so it's kind of cheating (as you're still using kernel space means to get the data delivered to user space) and may slow down networking due to the necessity of copying the first packet of the connection back and forth between kernel and user space (fortunately only for a single packet per connection). By the way, that's probably how Windows personal firewalls work too more or less which would also explain why networking (and whole computer experience as well) is slower on Windows when a firewall is active.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #24
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Checking a port if it's in use/open

    I am not assuming anything with you wysota. I am using multiple Linux distros and multiple Windows distros. To start assuming with you from your first post is just going to lead the thread further off topic, prevent me from working on the networking software I am working on right now, and create a list of assumptions that digress from a truth based reality; something I need in my life.

    FYI, I am working on a software's server and client networking script at the moment and it is using threading. The code is in Python and PyQt, so I am not using pure Qt classes I am also using Python classes.

    Query: Where is 'user land'?

  5. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking a port if it's in use/open

    Quote Originally Posted by prof.ebral View Post
    I am not assuming anything with you wysota. I am using multiple Linux distros and multiple Windows distros. To start assuming with you from your first post is just going to lead the thread further off topic, prevent me from working on the networking software I am working on right now, and create a list of assumptions that digress from a truth based reality; something I need in my life.
    Then I don't see why you're making opinions and defending them if you are not ready to make one more step and prove your points. It's easy to say "I don't have time to respond to your arguments, I have better things to do". Well, the truth is I'm devoting my private time to being here as well. The biggest compensation I can get is to study difficult cases such as this one and learn from them.

    FYI, I am working on a software's server and client networking script at the moment and it is using threading. The code is in Python and PyQt, so I am not using pure Qt classes I am also using Python classes.
    I don't care - you can write the proof of concept for your solution in pure python code even, I'm sure we'll understand the principles. The software doesn't even have to work, just show us the main idea.

    Query: Where is 'user land'?
    Everywhere where 'kernel land' is not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #26
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Checking a port if it's in use/open

    Then why don't you give me some time. I am rewriting the network and the current re-write is far from complete. If you want, you can download the source and see how the network uses threading.

    http://www.assembla.com/wiki/show/traipse

    The way the software's network is working: it uses threading to create new socks for each client, though all data is sent to one Port. It is pretty conceivable to use the same technology, only in reverse, to hand off the port request to a decision making function in the software. The function could notify the user through the UI and then the user could tell the software how to handle the request.

    While the port request is being made, yes the port will be used by a service, but after the decision is completed the software can stop using the port allowing it to be accessed.

  7. #27
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Checking a port if it's in use/open

    Quote Originally Posted by prof.ebral View Post
    Then why don't you give me some time. I am rewriting the network and the current re-write is far from complete. If you want, you can download the source and see how the network uses threading.
    Using threading to handle multiple connections is not a problem, but how do you pass a connection handled by a thread to another process?

  8. #28
    Join Date
    Feb 2010
    Location
    Hungary
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Checking a port if it's in use/open

    I will check the examples about network.
    Does somebody know other way to check if somebody connect to the pc with winvnc (on windows), than check the vnc's port?

  9. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking a port if it's in use/open

    The application probably logs a connection to some file in which case you can monitor the log file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #30
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Checking a port if it's in use/open

    Quote Originally Posted by sutee84 View Post
    Does somebody know other way to check if somebody connect to the pc with winvnc (on windows), than check the vnc's port?
    Have you taken a look at the VNC source code? The simplest solution may be to modify the code of VNC to popup a message box asking if you wish to accept the connection and show the IP address of the computer thats attempting to connect.

  11. #31
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Checking a port if it's in use/open

    Quote Originally Posted by fatjuicymole View Post
    Using threading to handle multiple connections is not a problem, but how do you pass a connection handled by a thread to another process?
    I don't know at the moment because that is not what I am working on.
    Quote Originally Posted by wysota View Post
    The application probably logs a connection to some file in which case you can monitor the log file.
    Please don't tell me you are talking about my application .. if you are, high rating or not check your ego at the source.

    EDIT: I think this thread has been unfortunately hijacked. I was just trying to point out that the OP's idea is possible. I didn't mean to hijack his question thread.
    Last edited by prof.ebral; 2nd March 2010 at 14:21. Reason: Sorry for hijacking your thread, Sutee. Computers are just tools that doo what you tell them, you just need to know how to tell them.

  12. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking a port if it's in use/open

    Quote Originally Posted by prof.ebral View Post
    I don't know at the moment because that is not what I am working on.
    That's the whole point of this discussion. We say this is not possible.

    Please don't tell me you are talking about my application .. if you are, high rating or not check your ego at the source.
    You may use the threaded or hybrid mode of the thread view to see which post I was replying to.

    EDIT: I think this thread has been unfortunately hijacked. I was just trying to point out that the OP's idea is possible. I didn't mean to hijack his question thread.
    And we're trying to point out it is not possible so the discussion is not offtopic.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #33
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Checking a port if it's in use/open

    Here is an example of what you want Sutee .. it is coded in Visual Basic so I am not sure how useful it will be to you here.

    Link: http://support.microsoft.com/kb/194938
    Last edited by prof.ebral; 2nd March 2010 at 16:34. Reason: forgot link

  14. #34
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Checking a port if it's in use/open

    meh. Here is the source for a Network Monitor coded in Qt: http://reachme.web.googlepages.com/qtnetworkmonitor

    filetransit.com makes this claim about it
    Qt Network Monitor 0.2 is an application to monitor the activity of both LANs and Internet servers, offering you continuous information about all devices: servers, computers, ports, websites, other IP devices, etc.It lets you monitor different devices simultaneously, and generates all types of statistics, obtained from each one of them.
    which is also what you want. The site I linked to is the main site for it and it contains the source .. so that might be something to look at Sutee. I can't find the same claim on the main page.

  15. The following user says thank you to prof.ebral for this useful post:

    sutee84 (2nd March 2010)

  16. #35
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking a port if it's in use/open

    I think you are missing the point of what sutee84 wants to do... He doesn't want to know on which ports there are daemons running, he wants to know when someone connects to one of the running daemons (despite the title of this thread).
    Last edited by wysota; 2nd March 2010 at 17:18.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #36
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Checking a port if it's in use/open

    You're welcome, Sutee. I don't expect you to use the softwares themselves, instead I thought you would be able to draw some information from them. They are not my softwares so I can verify the claims either. I hope you get what you are looking for.

    Some extra info: Firewall Builder is a Qt program that helps you write iptable/netfiler rules. As such it's only for Linux and MacOSX http://www.fwbuilder.org/
    But I did some extra research and found an open source Firewall for Windows called Netdefender. This has a Port scanner to scan for open ports: http://www.programmerworld.net/personal/firewall.htm This one is in Visual C++.

    Again same premise, draw from it what you can to get what you really want.

  18. #37
    Join Date
    Jan 2010
    Posts
    73
    Thanks
    6
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Checking a port if it's in use/open

    Take a look at the platform specific results here: http://en.wikipedia.org/wiki/Netstat

    This provides incite into how this information is obtained on different operating systems. I am not aware of this functionality being directly available in QT.

  19. #38
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Checking a port if it's in use/open

    After your replies in this forum, I really expected more than the posting of a quick google search. Pointing to the sourcecode of an open-source firewall is hardly practical either, specially considering it is written in Visual C++ and MFC when they were asking for Qt solution. I fail to see why you posted the other links, since they clearly do even less of what was asked.

  20. #39
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking a port if it's in use/open

    @fatjuicymole:

    Leave them alone, it seems they perfectly know what they want and what they are doing. At some point we have to admit we are just trolling around on this forum and bow our heads before a solution for detecting which tcp (won't work for udp) ports are open by trying to register a listening socket on each and every one of them. Let's face it - resistance is futile and even running a level three diagnostic wouldn't help.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  21. #40
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Checking a port if it's in use/open

    If you literally wish to see if a port is in use/open then the netstat command is probably what you need.

    Variations are built into the kernels of most operating systems.


    If you really want to build your own then something based around the pcap library or similar is what you need.

    Personally, I would not go there but good luck!

Similar Threads

  1. checking for mySql support in QT
    By aj2903 in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2009, 08:17
  2. Is there any spell checking in QTextEdit?
    By naoyamakino in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2009, 20:57
  3. StyleSheet syntax checking
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2008, 11:09
  4. Checking if bad pointer?
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2007, 10:06
  5. checking for null
    By drkbkr in forum General Programming
    Replies: 6
    Last Post: 13th March 2006, 22:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.