Search in sources :

Example 71 with InterfaceAddress

use of java.net.InterfaceAddress in project nd4j by deeplearning4j.

the class NetworkOrganizer method buildLocalInformation.

protected List<NetworkInformation> buildLocalInformation() {
    List<NetworkInformation> list = new ArrayList<>();
    NetworkInformation netInfo = new NetworkInformation();
    try {
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface networkInterface : interfaces) {
            if (!networkInterface.isUp())
                continue;
            for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
                String addr = address.getAddress().getHostAddress();
                if (addr == null || addr.isEmpty() || addr.contains(":"))
                    continue;
                netInfo.getIpAddresses().add(addr);
            }
        }
        list.add(netInfo);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return list;
}
Also used : InterfaceAddress(java.net.InterfaceAddress) NetworkInterface(java.net.NetworkInterface) ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException)

Example 72 with InterfaceAddress

use of java.net.InterfaceAddress in project mmupnp by ohmae.

the class SsdpServerDelegateTest method findInet6Address.

@Test
public void findInet6Address() throws Exception {
    final InterfaceAddress ipv4 = TestUtils.createInterfaceAddress("192.168.0.1", "255.255.255.0", 24);
    final InterfaceAddress ipv6 = TestUtils.createInterfaceAddress("fe80::a831:801b:8dc6:421f", "255.255.0.0", 16);
    assertThat(SsdpServerDelegate.findInet6Address(Arrays.asList(ipv4, ipv6)), is(ipv6));
    assertThat(SsdpServerDelegate.findInet6Address(Arrays.asList(ipv6, ipv4)), is(ipv6));
}
Also used : InterfaceAddress(java.net.InterfaceAddress) Test(org.junit.Test)

Example 73 with InterfaceAddress

use of java.net.InterfaceAddress in project mmupnp by ohmae.

the class SsdpServerDelegateTest method findInet4Address.

@Test
public void findInet4Address() throws Exception {
    final InterfaceAddress ipv4 = TestUtils.createInterfaceAddress("192.168.0.1", "255.255.255.0", 24);
    final InterfaceAddress ipv6 = TestUtils.createInterfaceAddress("fe80::a831:801b:8dc6:421f", "255.255.0.0", 16);
    assertThat(SsdpServerDelegate.findInet4Address(Arrays.asList(ipv4, ipv6)), is(ipv4));
    assertThat(SsdpServerDelegate.findInet4Address(Arrays.asList(ipv6, ipv4)), is(ipv4));
}
Also used : InterfaceAddress(java.net.InterfaceAddress) Test(org.junit.Test)

Example 74 with InterfaceAddress

use of java.net.InterfaceAddress in project mmupnp by ohmae.

the class TestUtils method createInterfaceAddress.

@Nonnull
public static InterfaceAddress createInterfaceAddress(final String address, final String broadcast, final int maskLength) throws ReflectiveOperationException, UnknownHostException {
    final InterfaceAddress interfaceAddress = Reflection.getConstructor(InterfaceAddress.class).newInstance();
    Reflection.setFieldValue(interfaceAddress, "address", InetAddress.getByName(address));
    Reflection.setFieldValue(interfaceAddress, "broadcast", InetAddress.getByName(broadcast));
    Reflection.setFieldValue(interfaceAddress, "maskLength", (short) maskLength);
    return interfaceAddress;
}
Also used : InterfaceAddress(java.net.InterfaceAddress) Nonnull(javax.annotation.Nonnull)

Example 75 with InterfaceAddress

use of java.net.InterfaceAddress in project mmupnp by ohmae.

the class SsdpMessageDelegateTest method getScopeId_インターフェースIPv4なら0.

@Test
public void getScopeId_インターフェースIPv4なら0() throws Exception {
    final byte[] data = TestUtils.getResourceAsByteArray("ssdp-notify-alive0.bin");
    final HttpRequest request = new HttpRequest().readData(new ByteArrayInputStream(data, 0, data.length));
    final InterfaceAddress ifa = TestUtils.createInterfaceAddress("192.0.2.3", "255.255.255.0", 0);
    final SsdpMessageDelegate delegate = new SsdpMessageDelegate(request, ifa);
    assertThat(delegate.getScopeId(), is(0));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InterfaceAddress(java.net.InterfaceAddress) Test(org.junit.Test)

Aggregations

InterfaceAddress (java.net.InterfaceAddress)104 NetworkInterface (java.net.NetworkInterface)69 InetAddress (java.net.InetAddress)60 SocketException (java.net.SocketException)27 Inet4Address (java.net.Inet4Address)26 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)18 IOException (java.io.IOException)9 Inet6Address (java.net.Inet6Address)8 UnknownHostException (java.net.UnknownHostException)7 NotifyListener (net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener)7 Command (com.android.server.NativeDaemonConnector.Command)6 LinkAddress (android.net.LinkAddress)5 DatagramPacket (java.net.DatagramPacket)5 List (java.util.List)5 InetSocketAddress (java.net.InetSocketAddress)4 SharedPreferences (android.content.SharedPreferences)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Enumeration (java.util.Enumeration)3 LinkedList (java.util.LinkedList)3