Search in sources :

Example 1 with Inet4Address

use of java.net.Inet4Address in project cw-omnibus by commonsguy.

the class WebServerService method raiseReadyEvent.

private void raiseReadyEvent() {
    ServerStartedEvent event = new ServerStartedEvent();
    try {
        for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
            NetworkInterface ni = enInterfaces.nextElement();
            for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
                InetAddress addr = enAddresses.nextElement();
                if (addr instanceof Inet4Address) {
                    event.addUrl("http://" + addr.getHostAddress() + ":4999" + rootPath + "/");
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    EventBus.getDefault().removeAllStickyEvents();
    EventBus.getDefault().postSticky(event);
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 2 with Inet4Address

use of java.net.Inet4Address in project cw-omnibus by commonsguy.

the class WebServerService method raiseReadyEvent.

private void raiseReadyEvent() {
    ServerStartedEvent event = new ServerStartedEvent();
    try {
        for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
            NetworkInterface ni = enInterfaces.nextElement();
            for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
                InetAddress addr = enAddresses.nextElement();
                if (addr instanceof Inet4Address) {
                    event.addUrl("http://" + addr.getHostAddress() + ":4999" + rootPath + "/");
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    EventBus.getDefault().removeAllStickyEvents();
    EventBus.getDefault().postSticky(event);
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 3 with Inet4Address

use of java.net.Inet4Address in project cw-omnibus by commonsguy.

the class WebServerService method raiseStartedEvent.

private void raiseStartedEvent() {
    ServerStartedEvent event = new ServerStartedEvent();
    try {
        for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
            NetworkInterface ni = enInterfaces.nextElement();
            for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
                InetAddress addr = enAddresses.nextElement();
                if (addr instanceof Inet4Address) {
                    event.addUrl("http://" + addr.getHostAddress() + ":4999");
                }
            }
        }
    } catch (SocketException e) {
        Log.e(getClass().getSimpleName(), "Exception in IP addresses", e);
    }
    EventBus.getDefault().removeAllStickyEvents();
    EventBus.getDefault().postSticky(event);
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 4 with Inet4Address

use of java.net.Inet4Address in project crate by crate.

the class PostgresNetty method resolveBindAddress.

private BoundTransportAddress resolveBindAddress() {
    // Bind and start to accept incoming connections.
    try {
        InetAddress[] hostAddresses = networkService.resolveBindHostAddresses(null);
        for (InetAddress address : hostAddresses) {
            if (address instanceof Inet4Address) {
                boundAddresses.add(bindAddress(address));
            }
        }
    } catch (IOException e) {
        throw new BindPostgresException("Failed to resolve binding network host", e);
    }
    final InetAddress publishInetAddress;
    try {
        publishInetAddress = networkService.resolvePublishHostAddresses(null);
    } catch (Exception e) {
        throw new BindTransportException("Failed to resolve publish address", e);
    }
    final int publishPort = resolvePublishPort(boundAddresses, publishInetAddress);
    final InetSocketAddress publishAddress = new InetSocketAddress(publishInetAddress, publishPort);
    return new BoundTransportAddress(boundAddresses.toArray(new TransportAddress[boundAddresses.size()]), new InetSocketTransportAddress(publishAddress));
}
Also used : Inet4Address(java.net.Inet4Address) InetSocketAddress(java.net.InetSocketAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) BindTransportException(org.elasticsearch.transport.BindTransportException) IOException(java.io.IOException) InetAddress(java.net.InetAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) BindTransportException(org.elasticsearch.transport.BindTransportException) BindHttpException(org.elasticsearch.http.BindHttpException) IOException(java.io.IOException)

Example 5 with Inet4Address

use of java.net.Inet4Address in project che by eclipse.

the class DefaultNetworkFinderHelperTest method checkFoundIpForABridge.

/**
     * Check that we can find ipv4 address if we have some bridge
     *
     * @throws SocketException
     */
@Test
public void checkFoundIpForABridge() throws SocketException {
    DefaultNetworkFinder networkFinder = new DefaultNetworkFinder();
    Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
    while (enumNetworkInterfaces.hasMoreElements()) {
        NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
        Optional<InetAddress> foundIpAddress = networkFinder.getIPAddress(networkInterface.getName());
        Enumeration<InetAddress> enumAddresses = networkInterface.getInetAddresses();
        List<InetAddress> list = new ArrayList<>();
        while (enumAddresses.hasMoreElements()) {
            InetAddress inetAddress = enumAddresses.nextElement();
            if (inetAddress instanceof Inet4Address) {
                list.add(inetAddress);
            }
        }
        if (list.size() > 0) {
            assertTrue(foundIpAddress.isPresent());
            assertTrue(list.contains(foundIpAddress.get()));
        }
    }
}
Also used : Inet4Address(java.net.Inet4Address) ArrayList(java.util.ArrayList) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress) Test(org.testng.annotations.Test)

Aggregations

Inet4Address (java.net.Inet4Address)184 InetAddress (java.net.InetAddress)85 Inet6Address (java.net.Inet6Address)45 NetworkInterface (java.net.NetworkInterface)39 UnknownHostException (java.net.UnknownHostException)28 LinkAddress (android.net.LinkAddress)24 SocketException (java.net.SocketException)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)19 InterfaceAddress (java.net.InterfaceAddress)17 ByteBuffer (java.nio.ByteBuffer)17 RouteInfo (android.net.RouteInfo)12 LinkProperties (android.net.LinkProperties)7 InetSocketAddress (java.net.InetSocketAddress)6 Test (org.junit.Test)6 WifiDisplay (android.hardware.display.WifiDisplay)5 WifiDisplaySessionInfo (android.hardware.display.WifiDisplaySessionInfo)5 DhcpResults (android.net.DhcpResults)5 IpConfiguration (android.net.IpConfiguration)5 IpAssignment (android.net.IpConfiguration.IpAssignment)5