I would like to find from a Java program if a particular port of the machine on which the program runs is free. I DO NOT want to bind to that port. I just want to identify if the port is free.
You can try a "brute force" method listed at http://www.javafaq.nu/java-example-code-637.html
Essentially it just loops through all the port numbers and executes the following code:
Socket theSocket = new Socket(host, i);
System.out.println("There is a server on port " + i + " of " + host);
I think technically you are not binding the port numbers this way since you close the socket as soon as you create it.
Hope this makes sense.
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.