Add method to find local free port

This commit is contained in:
crschnick
2024-04-05 12:34:32 +00:00
parent 6d88d3926d
commit b3e2878ff6
@@ -1,9 +1,17 @@
package io.xpipe.app.util;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.Locale;
public class HostHelper {
public static int findRandomOpenPortOnAllLocalInterfaces() throws IOException {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
}
}
public static boolean isLocalHost(String host) {
if (host.equals("127.0.0.1")) {
return true;