1

OS: Windows Server 2003

Is there any tool that can test if a certain port is available for my program to listen to? Thanks.

3 Answers 3

2

For windows: netstat will show you existing port numbers - just pick one that's not used.

To see what ports are listening on a machine - nmap the machine.

To verify that it's your program getting the input properly - telnet to that port and then type stuff and see if your program gets it.

1

Might want to first become aware of possible port conflicts by checking out a list of common ports uses: http://www.iana.org/assignments/port-numbers

You can see what ports are being listened too at the time by using netstat as @robert has said. :http://www.petri.co.il/quickly_find_local_open_ports.htm

You can test if a port is accessable form the outside by using one of several online port scanners: http://www.canyouseeme.org/

And finally, check that the port is not being blocked: http://support.microsoft.com/kb/816792

1

I think the general idea is usually that your program should try to bind to the port with a function and then you would check the return value to make sure the bind was successful. If unsuccessful, you error out. This is coming from a *nix perspective, but I was under the impression this is pretty universal.

The reason I feel that it is universal is that ideally the check port and bind to port would need to be atomic. This, in this usage means that no other program has a chance of using the port between when check is done and the port is allocated. In case like using something like netstat first, it is possible between your check and trying to use the port something else will have used it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .