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;
}
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));
}
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));
}
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;
}
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));
}
Aggregations