import java.net.*;

public class GetPort{
    public static void main(String args[]) {
        try{
            DatagramSocket socketA = null;
            DatagramSocket socketB = null;
        
            socket = new DatagramSocket();
            
            System.out.println("Free port: " + socket.getLocalPort());
            
            socket.close();
        }
        catch (Exception e) {
            System.err.println("ERROR: " + e);
            e.printStackTrace(System.out);
        }
    }
}
