0

Working on an application that uses cameras.

The camera controller has a single IP address (I can define that IP) on the network and each camera is accessed using that IP plus a Port. The controller can have up to 250 cameras.

Currently there are three cameras and I want to be able to assign Ports in lumps, as in... 6510, (Reception) 6520, (Dock) 6530 (Parking Lot) such that I can add extra cameras and assign Ports appropriate to the camera's physical location, as in... 6510 and 6511 will be physically close to each other, as would 6520, 6521 and 6522 be close.

How can I find a range of available Ports? I have searched the Internet and found a few sites that outline commonly used Port numbers, but I would like to find a free-range for the individual PC the software is installed on.

How can I scan for unused Ports?

3
  • There only is two possibilities: 1) your cameras connect to some server and advertise where they are and what ports do they use - for example google for ZeroConf and dynamic DNS or 2) you program does "probing": connects every possible port and tries to communicate with camera. If there is non-camera service there communication would fail and the program would connect to port+1 Nov 8, 2013 at 16:32
  • 2
    This is not a programming task. This is a system-administration task. Just pick a range of ports and reserve them on your computer. Netstat will show you which ports are currently in use; just pick some that aren't. Nov 8, 2013 at 16:47
  • Do you mean which port on the PC? If so, check out superuser.com/questions/451348/…
    – Dave
    Dec 20, 2013 at 8:47

1 Answer 1

1

Unless you register your port numbers with IANA, other programs may try to bind to the same port (it may already be in use by another application). Even if you registered your port numbers, other programs that don't heed the standards may still try to bind to the same port.

Since you require a large number of ports and a non-specific number of ports, you probably will not have any luck registering the ports with IANA.

Therefore, you should use ports >= 49151. The standard practice is to attempt to bind to a port, and if it's in use, the bind will fail. You catch the exception and try the next port.

There is nothing that lists free ports, but you can get in-use ports. Ports range from 1 to 65535, so you can figure out the list of free ports with the list of in-use ports. I find that quite often, the list of in-use ports will show false positives. Eg. ports may show as in use that aren't actually in use any more, but eventually they clear up over time.

So, if you need blocks of free ports, you can derive that list from the in-use ports.

Your server may wish to host the list of ports that it's using via a web server on the known port 80. Client/server communication relies on having at least one known port that the client can use to connect to the server.

You must log in to answer this question.