org.jgroups.tests.GetGlobalAddress Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including
all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and
Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
package org.jgroups.tests;
import org.jgroups.util.Util;
import java.net.InetAddress;
import java.net.SocketException;
/**
* Returns a global IP address, if not found a site-local, if not found a non loopback, if not found the loopback addr
* @author Bela Ban
*/
public class GetGlobalAddress {
public static void main(String[] args) {
try {
InetAddress addr=Util.getAddress(Util.AddressScope.GLOBAL);
if(addr != null) {
System.out.println(addr.getHostAddress());
return;
}
addr=Util.getAddress(Util.AddressScope.SITE_LOCAL);
if(addr != null) {
System.out.println(addr.getHostAddress());
return;
}
addr=Util.getAddress(Util.AddressScope.NON_LOOPBACK);
if(addr != null) {
System.out.println(addr.getHostAddress());
return;
}
addr=Util.getAddress(Util.AddressScope.LOOPBACK);
if(addr != null) {
System.out.println(addr.getHostAddress());
}
}
catch(SocketException e) {
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy