Java Code Examples for java.net.Inet6Address#getByName()

The following examples show how to use java.net.Inet6Address#getByName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Ipv6Test.java    From javahost with Apache License 2.0 6 votes vote down vote up
@Test
public void ipv6() throws UnknownHostException {
	InetAddress address = Inet6Address.getByName("ipv6.leopard.io");
	String ip = address.getHostAddress();
	System.out.println("ip:" + ip);

	JavaHost.queryIp("leopard.io");

	Map<String, String> map = new HashMap<String, String>();
	map.put("javahost1.leopard.io", "127.0.0.1");
	map.put("javahost2.leopard.io", "127.0.0.2");
	map.put("javahost6.leopard.io", "fe80::a178:9e5e:47d:5df3%14");

	JavaHost.updateVirtualDns(map);
	JavaHost.printAllVirtualDns();
}
 
Example 2
Source File: UrlSanitizerUtils.java    From gravitee-management-rest-api with Apache License 2.0 6 votes vote down vote up
public static boolean isPrivate(String url) {

        try {
            InetAddress inetAddress = Inet6Address.getByName(new URL(url).getHost());

            return inetAddress.isSiteLocalAddress()
                    || inetAddress.isAnyLocalAddress()
                    || inetAddress.isLoopbackAddress()
                    || inetAddress.isLinkLocalAddress()
                    || inetAddress.isMulticastAddress()
                    || isPrivateOwasp(inetAddress.getHostAddress());

        } catch (Exception e) {

            throw new InvalidDataException("Url [" + url + "] is invalid");
        }
    }
 
Example 3
Source File: PgBulkInsertTest.java    From PgBulkInsert with MIT License 6 votes vote down vote up
@Test
public void saveAll_Inet6_Test() throws SQLException, UnknownHostException {

    // This list will be inserted.
    List<SampleEntity> entities = new ArrayList<>();

    // Create the Entity to insert:
    SampleEntity entity = new SampleEntity();
    entity.col_inet6Address = (Inet6Address) Inet6Address.getByName("1080::8:800:200c:417a");

    entities.add(entity);

    PgBulkInsert<SampleEntity> pgBulkInsert = new PgBulkInsert<>(new SampleEntityMapping());

    pgBulkInsert.saveAll(PostgreSqlUtils.getPGConnection(connection), entities.stream());

    ResultSet rs = getAll();

    while (rs.next()) {
        String v = rs.getString("col_inet6");
        Assert.assertEquals("1080::8:800:200c:417a", v);
    }
}
 
Example 4
Source File: IIPDataReceiveListenerIPv6Test.java    From xbee-java with Mozilla Public License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupOnce() throws Exception {
	sourceAddress = (Inet6Address) Inet6Address.getByName(IPV6_SRC_ADDRESS);
	destAddress = (Inet6Address) Inet6Address.getByName(IPV6_DST_ADDRESS);
	
	// Mock RX IPV4 Packet.
	rxIPv6Packet = Mockito.mock(RXIPv6Packet.class);
	Mockito.when(rxIPv6Packet.getFrameType()).thenReturn(APIFrameType.RX_IPV6);
	Mockito.when(rxIPv6Packet.getSourcePort()).thenReturn(SOURCE_PORT);
	Mockito.when(rxIPv6Packet.getDestPort()).thenReturn(DEST_PORT);
	Mockito.when(rxIPv6Packet.getProtocol()).thenReturn(PROTOCOL);
	Mockito.when(rxIPv6Packet.getData()).thenReturn(RECEIVED_DATA_BYTES);
	Mockito.when(rxIPv6Packet.getSourceAddress()).thenReturn(sourceAddress);
	Mockito.when(rxIPv6Packet.getDestAddress()).thenReturn(destAddress);
	
	// Mock an invalid packet.
	invalidPacket = Mockito.mock(ATCommandResponsePacket.class);
	
	// Mock the XBee device.
	xbeeDevice = Mockito.mock(XBeeDevice.class);
}
 
Example 5
Source File: TXIPv6PacketTest.java    From xbee-java with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Test method for {@link com.digi.xbee.api.packet.thread.TXIPv6Packet#setDestAddress(Inet6Address)}.
 *
 * @throws Exception
 */
@Test
public final void testSetDestAddressNotNull() throws Exception {
	// Set up the resources for the test.
	TXIPv6Packet packet = new TXIPv6Packet(frameID, destAddress, destPort, sourcePort, protocol, data);

	Inet6Address newAddress = (Inet6Address) Inet6Address.getByName("fd8a:cb11:ad71:0000:7662:c401:5efe:dc41");

	// Call the method under test.
	packet.setDestAddress(newAddress);

	// Verify the result.
	assertThat("Dest address is not the expected one", packet.getDestAddress(), is(equalTo(newAddress)));
}
 
Example 6
Source File: RXIPv6PacketTest.java    From xbee-java with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Test method for {@link com.digi.xbee.api.packet.thread.RXIPv6Packet#setSourceAddress(Inet6Address)}.
 *
 * @throws Exception
 */
@Test
public final void testSetSourceAddressNotNull() throws Exception {
	// Set up the resources for the test.
	RXIPv6Packet packet = new RXIPv6Packet(destAddress, sourceAddress, destPort, sourcePort, protocol, data);

	Inet6Address newAddress = (Inet6Address) Inet6Address.getByName("FDB3:0001:0002:0000:0004:0005:0006:0088");

	// Call the method under test.
	packet.setSourceAddress(newAddress);

	// Verify the result.
	assertThat("Source address is not the expected one", packet.getSourceAddress(), is(equalTo(newAddress)));
}
 
Example 7
Source File: ThreadDeviceTest.java    From xbee-java with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Test method for {@link com.digi.xbee.api.ThreadDevice#sendIPDataAsync(Inet6Address, int, IPProtocol, byte[])
 * 
 * <p>Verify that TCP protocol is not supported when sending IPv6 data asynchronously.</p>
 * 
 * @throws Exception
 */
@Test
public void testSendIPDataAsyncProtocolIllegalTCP() throws Exception {
	// Set up the resources for the test.
	Inet6Address address = (Inet6Address) Inet6Address.getByName("FDB3:0001:0002:0000:0004:0005:0006:0007");
	byte[] data = "Hello XBee".getBytes();
	int destPort = 1234;
	
	exception.expect(IllegalArgumentException.class);
	exception.expectMessage(is(equalTo(String.format("Protocol must be %s or %s.", 
			IPProtocol.UDP.getName(), IPProtocol.COAP.getName()))));
	
	// Call the method under test that should throw an IllegalArgumentException.
	threadDevice.sendIPDataAsync(address, destPort, IPProtocol.TCP, data);
}
 
Example 8
Source File: PlatformTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void produceLinkLocalIp_siteLocal_ipv6() throws Exception {
  InetAddress ipv6 = Inet6Address.getByName("fec0:db8::c001");
  nicWithAddress(ipv6);

  assertThat(platform.produceLinkLocalIp())
    .isEqualTo(ipv6.getHostAddress());
}
 
Example 9
Source File: CoAPTxRequestPacketTest.java    From xbee-java with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Test method for {@link com.digi.xbee.api.packet.thread.CoAPTxRequestPacket#setDestAddress(Inet6Address)}.
 *
 * @throws Exception
 */
@Test
public final void testSetDestAddressNotNull() throws Exception {
	// Set up the resources for the test.
	CoAPTxRequestPacket packet = new CoAPTxRequestPacket(frameID, options, method, destAddress, uriData, data);

	Inet6Address newAddress = (Inet6Address) Inet6Address.getByName("fd8a:cb11:ad71:0000:7662:c401:5efe:dc41");

	// Call the method under test.
	packet.setDestAddress(newAddress);

	// Verify the result.
	assertThat("Dest address is not the expected one", packet.getDestAddress(), is(equalTo(newAddress)));
}
 
Example 10
Source File: SendIPv6DataAsyncTest.java    From xbee-java with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
	ipv6Address = (Inet6Address) Inet6Address.getByName(IPV6_ADDRESS);
	
	// Instantiate a IPv6Device object with a mocked interface.
	ipv6Device = PowerMockito.spy(new IPv6Device(Mockito.mock(SerialPortRxTx.class)));
	
	// Mock TX IPv6 packet.
	txIPv6Packet = Mockito.mock(TXIPv6Packet.class);
	
	// Whenever a TXIPv6Packet class is instantiated, the mocked txIPv6Packet packet should be returned.
	PowerMockito.whenNew(TXIPv6Packet.class).withAnyArguments().thenReturn(txIPv6Packet);
}
 
Example 11
Source File: CoAPRxResponsePacketTest.java    From xbee-java with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Test method for {@link com.digi.xbee.api.packet.thread.CoAPRxResponsePacket#setDestAddress(Inet6Address)}.
 *
 * @throws Exception
 */
@Test
public final void testSetDestAddressNotNull() throws Exception {
	// Set up the resources for the test.
	CoAPRxResponsePacket packet = new CoAPRxResponsePacket(frameID, destAddress, sourceAddress, destPort, sourcePort, protocol, restFulStatus, data);

	Inet6Address newAddress = (Inet6Address) Inet6Address.getByName("FDB3:0001:0002:0000:0004:0005:0006:0088");

	// Call the method under test.
	packet.setDestAddress(newAddress);

	// Verify the result.
	assertThat("Destination address is not the expected one", packet.getDestAddress(), is(equalTo(newAddress)));
}
 
Example 12
Source File: SetDestinationIPv6AddressTest.java    From xbee-java with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
	ADDRESS = (Inet6Address) Inet6Address.getByName("FDB3:0001:0002:0000:0004:0005:0006:0007");

	// Instantiate a local Thread device object.
	xbeeDevice = PowerMockito.spy(new ThreadDevice(Mockito.mock(SerialPortRxTx.class)));
}
 
Example 13
Source File: XBeePacketsQueueTest.java    From xbee-java with Mozilla Public License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupOnce() throws Exception {
	// Create 3 64-bit addresses.
	xbee64BitAddress1 = new XBee64BitAddress(ADDRESS_64_1);
	xbee64BitAddress2 = new XBee64BitAddress(ADDRESS_64_2);
	xbee64BitAddress3 = new XBee64BitAddress(ADDRESS_64_3);
	
	// Create a couple of 16-bit addresses.
	xbee16BitAddress1 = new XBee16BitAddress(ADDRESS_16_1);
	xbee16BitAddress2 = new XBee16BitAddress(ADDRESS_16_2);
	
	// Create a couple of IP addresses.
	ipAddress1 = (Inet4Address) Inet4Address.getByName(ADDRESS_IP_1);
	ipAddress2 = (Inet4Address) Inet4Address.getByName(ADDRESS_IP_2);
	
	// Create a couple of IPv6 addresses.
	ipv6Address1 = (Inet6Address) Inet6Address.getByName(ADDRESS_IPV6_1);
	ipv6Address2 = (Inet6Address) Inet6Address.getByName(ADDRESS_IPV6_2);
	
	// Create some dummy packets.
	// ReceivePacket.
	mockedReceivePacket = Mockito.mock(ReceivePacket.class);
	Mockito.when(mockedReceivePacket.getFrameType()).thenReturn(APIFrameType.RECEIVE_PACKET);
	// RemoteATCommandResponsePacket.
	mockedRemoteATCommandPacket = Mockito.mock(RemoteATCommandResponsePacket.class);
	Mockito.when(mockedRemoteATCommandPacket.getFrameType()).thenReturn(APIFrameType.REMOTE_AT_COMMAND_RESPONSE);
	// RX64IOPacket.
	mockedRxIO64Packet = Mockito.mock(RX64IOPacket.class);
	Mockito.when(mockedRxIO64Packet.getFrameType()).thenReturn(APIFrameType.RX_IO_64);
	// RX16IOPacket.
	mockedRxIO16Packet = Mockito.mock(RX16IOPacket.class);
	Mockito.when(mockedRxIO16Packet.getFrameType()).thenReturn(APIFrameType.RX_IO_16);
	// RX64Packet.
	mockedRx64Packet = Mockito.mock(RX64Packet.class);
	Mockito.when(mockedRx64Packet.getFrameType()).thenReturn(APIFrameType.RX_64);
	// RX16Packet.
	mockedRx16Packet = Mockito.mock(RX16Packet.class);
	Mockito.when(mockedRx16Packet.getFrameType()).thenReturn(APIFrameType.RX_16);
	// ExplicitRxIndicatorPacket.
	mockedExplicitRxIndicatorPacket = Mockito.mock(ExplicitRxIndicatorPacket.class);
	Mockito.when(mockedExplicitRxIndicatorPacket.getFrameType()).thenReturn(APIFrameType.EXPLICIT_RX_INDICATOR);
	// RXIPv4Packet.
	mockedRxIPv4Packet = Mockito.mock(RXIPv4Packet.class);
	Mockito.when(mockedRxIPv4Packet.getFrameType()).thenReturn(APIFrameType.RX_IPV4);
	mockedRxIPv4Packet2 = Mockito.mock(RXIPv4Packet.class);
	Mockito.when(mockedRxIPv4Packet2.getFrameType()).thenReturn(APIFrameType.RX_IPV4);
	// RXIPv6Packet.
	mockedRxIPv6Packet = Mockito.mock(RXIPv6Packet.class);
	Mockito.when(mockedRxIPv6Packet.getFrameType()).thenReturn(APIFrameType.RX_IPV6);
	mockedRxIPv6Packet2 = Mockito.mock(RXIPv6Packet.class);
	Mockito.when(mockedRxIPv6Packet2.getFrameType()).thenReturn(APIFrameType.RX_IPV6);
}
 
Example 14
Source File: IPMessageTest.java    From xbee-java with Mozilla Public License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupOnce() throws Exception {
	ipAddress = (Inet4Address) Inet4Address.getByName(IP_ADDRESS);
	ipv6Address = (Inet6Address) Inet6Address.getByName(IPV6_ADDRESS);
}
 
Example 15
Source File: TXIPv6PacketTest.java    From xbee-java with Mozilla Public License 2.0 4 votes vote down vote up
public TXIPv6PacketTest() throws Exception {
	destAddress = (Inet6Address) Inet6Address.getByName(IPV6_ADDRESS);
}
 
Example 16
Source File: IPv6AddressTest.java    From java-ipv6 with Apache License 2.0 4 votes vote down vote up
@Test
public void convertToInet6Address() throws UnknownHostException
{
    final InetAddress inetAddress = Inet6Address.getByName("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
    assertEquals(inetAddress, fromString("2001:0db8:85a3:0000:0000:8a2e:0370:7334").toInetAddress());
}
 
Example 17
Source File: IPv6RemoteATCommandResponsePacketTest.java    From xbee-java with Mozilla Public License 2.0 4 votes vote down vote up
public IPv6RemoteATCommandResponsePacketTest() throws Exception {
	ipv6address = (Inet6Address) Inet6Address.getByName(IPV6_ADDR);
}
 
Example 18
Source File: RXIPv6PacketTest.java    From xbee-java with Mozilla Public License 2.0 4 votes vote down vote up
public RXIPv6PacketTest() throws Exception {
	sourceAddress = (Inet6Address) Inet6Address.getByName(IPV6_SRC_ADDRESS);
	destAddress = (Inet6Address) Inet6Address.getByName(IPV6_DST_ADDRESS);
}
 
Example 19
Source File: IPv6AddressTest.java    From java-ipv6 with Apache License 2.0 4 votes vote down vote up
@Test
public void constructFromInet6Address() throws UnknownHostException
{
    final InetAddress inetAddress = Inet6Address.getByName("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
    assertEquals("2001:db8:85a3::8a2e:370:7334", fromInetAddress(inetAddress).toString());
}
 
Example 20
Source File: IPv6IODataSampleRxIndicatorTest.java    From xbee-java with Mozilla Public License 2.0 4 votes vote down vote up
public IPv6IODataSampleRxIndicatorTest() throws Exception {
	ipv6address = (Inet6Address) Inet6Address.getByName(IPV6_ADDR);
}