use of java.net.NetworkInterface in project dubbo by alibaba.
the class PerformanceUtils method getEnvironment.
public static List<String> getEnvironment() {
List<String> environment = new ArrayList<String>();
environment.add("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch", ""));
environment.add("CPU: " + Runtime.getRuntime().availableProcessors() + " cores");
environment.add("JVM: " + System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version"));
environment.add("Memory: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().totalMemory()) + " bytes (Max: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().maxMemory()) + " bytes)");
NetworkInterface ni = PerformanceUtils.getNetworkInterface();
if (ni != null) {
environment.add("Network: " + ni.getDisplayName());
}
return environment;
}
use of java.net.NetworkInterface in project dubbo by alibaba.
the class PerformanceUtils method getEnvironment.
public static List<String> getEnvironment() {
List<String> environment = new ArrayList<String>();
environment.add("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch", ""));
environment.add("CPU: " + Runtime.getRuntime().availableProcessors() + " cores");
environment.add("JVM: " + System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version"));
environment.add("Memory: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().totalMemory()) + " bytes (Max: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().maxMemory()) + " bytes)");
NetworkInterface ni = PerformanceUtils.getNetworkInterface();
if (ni != null) {
environment.add("Network: " + ni.getDisplayName());
}
return environment;
}
use of java.net.NetworkInterface in project Openfire by igniterealtime.
the class STUNService method getAddresses.
public List<InetAddress> getAddresses() {
List<InetAddress> list = new ArrayList<InetAddress>();
try {
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
while (iaddresses.hasMoreElements()) {
InetAddress iaddress = iaddresses.nextElement();
if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress()) {
list.add(iaddress);
}
}
}
} catch (Exception e) {
// Do Nothing
}
return list;
}
use of java.net.NetworkInterface in project Smack by igniterealtime.
the class BasicResolver method resolve.
/**
* Resolve the IP address.
* <p/>
* The BasicResolver takes the IP addresses of the interfaces and uses the
* first non-loopback, non-linklocal and non-sitelocal address.
* @throws NotConnectedException
* @throws InterruptedException
*/
@Override
public synchronized void resolve(JingleSession session) throws XMPPException, NotConnectedException, InterruptedException {
setResolveInit();
clearCandidates();
Enumeration<NetworkInterface> ifaces = null;
try {
ifaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
LOGGER.log(Level.WARNING, "exception", e);
}
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
while (iaddresses.hasMoreElements()) {
InetAddress iaddress = iaddresses.nextElement();
if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress() && !iaddress.isSiteLocalAddress()) {
TransportCandidate tr = new TransportCandidate.Fixed(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName(), getFreePort());
tr.setLocalIp(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName());
addCandidate(tr);
setResolveEnd();
return;
}
}
}
try {
ifaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
LOGGER.log(Level.WARNING, "exception", e);
}
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
while (iaddresses.hasMoreElements()) {
InetAddress iaddress = iaddresses.nextElement();
if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress()) {
TransportCandidate tr = new TransportCandidate.Fixed(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName(), getFreePort());
tr.setLocalIp(iaddress.getHostAddress() != null ? iaddress.getHostAddress() : iaddress.getHostName());
addCandidate(tr);
setResolveEnd();
return;
}
}
}
try {
TransportCandidate tr = new TransportCandidate.Fixed(InetAddress.getLocalHost().getHostAddress() != null ? InetAddress.getLocalHost().getHostAddress() : InetAddress.getLocalHost().getHostName(), getFreePort());
tr.setLocalIp(InetAddress.getLocalHost().getHostAddress() != null ? InetAddress.getLocalHost().getHostAddress() : InetAddress.getLocalHost().getHostName());
addCandidate(tr);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
}
setResolveEnd();
}
use of java.net.NetworkInterface in project Smack by igniterealtime.
the class BridgedResolver method getLocalHost.
public static String getLocalHost() {
Enumeration<NetworkInterface> ifaces = null;
try {
ifaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
LOGGER.log(Level.WARNING, "exception", e);
}
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
while (iaddresses.hasMoreElements()) {
InetAddress iaddress = iaddresses.nextElement();
if (!iaddress.isLoopbackAddress() && !iaddress.isLinkLocalAddress() && !iaddress.isSiteLocalAddress() && !(iaddress instanceof Inet6Address)) {
return iaddress.getHostAddress();
}
}
}
try {
return InetAddress.getLocalHost().getHostAddress();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
}
return "127.0.0.1";
}
Aggregations