mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-05-29 16:11:03 +00:00
Add method to find local free port
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user