
com.github.panhongan.utils.host.HostUtils Maven / Gradle / Ivy
package com.github.panhongan.utils.host;
import javax.annotation.Nonnull;
import java.net.InetAddress;
import java.util.function.Supplier;
/**
* lalalu plus
*/
public class HostUtils {
private static Supplier hostNameSupplier = () -> getHostExec();
private static Supplier ipSupplier = () -> getIpExec();
@Nonnull
public static String getHostName() {
return hostNameSupplier.get();
}
@Nonnull
public static String getIp() {
return ipSupplier.get();
}
private static String getHostExec() {
try {
InetAddress host = InetAddress.getLocalHost();
return (host != null ? host.getHostName() : null);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
private static String getIpExec() {
try {
return InetAddress.getByName(getHostName()).getHostAddress();
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy