Search in sources :

Example 21 with NetworkInterface

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;
}
Also used : ArrayList(java.util.ArrayList) NetworkInterface(java.net.NetworkInterface)

Example 22 with NetworkInterface

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;
}
Also used : ArrayList(java.util.ArrayList) NetworkInterface(java.net.NetworkInterface)

Example 23 with NetworkInterface

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;
}
Also used : ArrayList(java.util.ArrayList) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) SocketException(java.net.SocketException)

Example 24 with NetworkInterface

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();
}
Also used : SocketException(java.net.SocketException) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress) SocketException(java.net.SocketException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 25 with NetworkInterface

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";
}
Also used : SocketException(java.net.SocketException) NetworkInterface(java.net.NetworkInterface) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress) SmackException(org.jivesoftware.smack.SmackException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) SocketException(java.net.SocketException) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

NetworkInterface (java.net.NetworkInterface)225 InetAddress (java.net.InetAddress)178 SocketException (java.net.SocketException)112 ArrayList (java.util.ArrayList)42 Inet4Address (java.net.Inet4Address)39 UnknownHostException (java.net.UnknownHostException)36 InterfaceAddress (java.net.InterfaceAddress)32 Inet6Address (java.net.Inet6Address)29 IOException (java.io.IOException)25 Enumeration (java.util.Enumeration)9 InetSocketAddress (java.net.InetSocketAddress)7 HashSet (java.util.HashSet)7 LinkedHashSet (java.util.LinkedHashSet)7 Command (com.android.server.NativeDaemonConnector.Command)6 Test (org.junit.Test)6 DatagramSocket (java.net.DatagramSocket)5 File (java.io.File)4 MulticastSocket (java.net.MulticastSocket)4 List (java.util.List)4 SharedPreferences (android.content.SharedPreferences)3