@Test public void testTableInputFormatBaseReverseDNSForIPv6() throws UnknownHostException { String address = "ipv6.google.com"; String localhost = null; InetAddress addr = null; TableInputFormat inputFormat = new TableInputFormat(); try { localhost = InetAddress.getByName(address).getCanonicalHostName(); addr = Inet6Address.getByName(address); } catch (UnknownHostException e) { // google.com is down, we can probably forgive this test. return; } System.out.println("Should retrun the hostname for this host " + localhost + " addr : " + addr); String actualHostName = inputFormat.reverseDNS(addr); assertEquals("Should retrun the hostname for this host. Expected : " + localhost + " Actual : " + actualHostName, localhost, actualHostName); }
InetSocketAddress node2 = new InetSocketAddress(InetAddress.getLocalHost(), 1001); InetSocketAddress node3 = new InetSocketAddress( Inet6Address.getByName("2001:0db8:85a3:08d3:1319:47ff:fe3b:7fd3"), 1002);
@Test // IPv6 is disabled: We only get IPv4 servers through public void testNewDNSServer_ipv6disabled() throws Exception { byte[] ipv6Template = new byte[]{32, 1, 13, (byte) (184 & 0xFF), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; InetAddress i6addr = Inet6Address.getByName("::1"); thread.newDNSServer(builder, "192.168.0.%d", null, i6addr); assertTrue(serversAdded.isEmpty()); assertTrue(thread.upstreamDnsServers.isEmpty()); InetAddress i4addr = Inet4Address.getByName("127.0.0.1"); thread.newDNSServer(builder, "192.168.0.%d", null, i4addr); assertTrue(serversAdded.contains(InetAddress.getByName("192.168.0.2"))); assertTrue(thread.upstreamDnsServers.contains(i4addr)); }
@Test // Everything works fine, everyone gets through. public void testNewDNSServer() throws Exception { String format = "192.168.0.%d"; byte[] ipv6Template = new byte[]{32, 1, 13, (byte) (184 & 0xFF), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; InetAddress i6addr = Inet6Address.getByName("::1"); InetAddress i4addr = Inet4Address.getByName("127.0.0.1"); thread.newDNSServer(builder, format, ipv6Template, i4addr); assertTrue(thread.upstreamDnsServers.contains(i4addr)); assertTrue(serversAdded.contains(InetAddress.getByName("192.168.0.2"))); thread.newDNSServer(builder, format, ipv6Template, i6addr); assertTrue(thread.upstreamDnsServers.contains(i6addr)); assertEquals(3, ipv6Template[ipv6Template.length - 1]); assertTrue(serversAdded.contains(InetAddress.getByAddress(ipv6Template))); }
@Test // IPv4 is disabled: We only get IPv6 servers through public void testNewDNSServer_ipv4disabled() throws Exception { String format = "192.168.0.%d"; byte[] ipv6Template = new byte[]{32, 1, 13, (byte) (184 & 0xFF), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; InetAddress i6addr = Inet6Address.getByName("::1"); InetAddress i4addr = Inet4Address.getByName("127.0.0.1"); thread.newDNSServer(builder, null, ipv6Template, i4addr); assertTrue(thread.upstreamDnsServers.isEmpty()); assertTrue(serversAdded.isEmpty()); thread.newDNSServer(builder, format, ipv6Template, i6addr); assertTrue(thread.upstreamDnsServers.contains(i6addr)); assertEquals(2, ipv6Template[ipv6Template.length - 1]); assertTrue(serversAdded.contains(InetAddress.getByAddress(ipv6Template))); }
@Test public void testHasIpV6Servers() throws Exception { Configuration.Item item0 = new Configuration.Item(); Configuration.Item item1 = new Configuration.Item(); config.ipV6Support = true; config.dnsServers.enabled = true; config.dnsServers.items.add(item0); config.dnsServers.items.add(item1); item0.location = "::1"; item0.state = Configuration.Item.STATE_ALLOW; item1.location = "127.0.0.1"; item1.state = Configuration.Item.STATE_ALLOW; Set<InetAddress> servers = new HashSet<>(); assertTrue(thread.hasIpV6Servers(config, servers)); config.ipV6Support = false; assertFalse(thread.hasIpV6Servers(config, servers)); config.ipV6Support = true; item0.state = Configuration.Item.STATE_DENY; assertFalse(thread.hasIpV6Servers(config, servers)); servers.add(Inet6Address.getByName("127.0.0.1")); assertFalse(thread.hasIpV6Servers(config, servers)); servers.add(Inet6Address.getByName("::1")); assertTrue(thread.hasIpV6Servers(config, servers)); }
protected Object convertToObject(final String text) throws Exception { return Inet6Address.getByName(text); } }
/** * * @param address IPv6 address * @return <code>true</code> if the specified address is valid */ private boolean isValidIPv6Address( String address ) { try { java.net.Inet6Address.getByName(address); return true; } catch (Exception e) { return false; } }
protected Object toObjectImpl(String text) { try { return Inet6Address.getByName(text); } catch (UnknownHostException e) { throw new PropertyEditorException(e); } } }
protected Object toObjectImpl(String text) { try { return Inet6Address.getByName(text); } catch (UnknownHostException e) { throw new PropertyEditorException(e); } } }
public static void main(String[] args) throws IOException { Inet6Address server = (Inet6Address) Inet6Address.getByName(HOST); System.out.println("Lookup: " + server); Socket clientSocket; // clientSocket = new Socket(server, DAYTIME_PORT); clientSocket = new Socket("fe80::203:93ff:fe07:3ef6", DAYTIME_PORT); System.out.println(clientSocket); BufferedReader is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); String dateString = is.readLine(); System.out.println(dateString); is.close(); clientSocket.close(); } }
public byte[] toByteArray() { if( !isValid() ) { return null; } try { return Inet6Address.getByName(input).getAddress(); // XXX is this ok or is there another way? } catch(UnknownHostException e) { return null; } }
public InetAddress toInetAddress() throws UnknownHostException { return Inet6Address.getByName(toString()); }
public boolean resolve(IpPacket parsedPacket, DnsMessage dnsMsg) { String dnsQueryName = dnsMsg.getQuestion().name.toString(); try { String response = RuleResolver.resolve(dnsQueryName, dnsMsg.getQuestion().type); if (response != null && dnsMsg.getQuestion().type == Record.TYPE.A) { Logger.info("Provider: Resolved " + dnsQueryName + " Local resolver response: " + response); DnsMessage.Builder builder = dnsMsg.asBuilder() .setQrFlag(true) .addAnswer(new Record<>(dnsQueryName, Record.TYPE.A, 1, 64, new A(Inet4Address.getByName(response).getAddress()))); handleDnsResponse(parsedPacket, builder.build().toArray()); return true; } else if (response != null && dnsMsg.getQuestion().type == Record.TYPE.AAAA) { Logger.info("Provider: Resolved " + dnsQueryName + " Local resolver response: " + response); DnsMessage.Builder builder = dnsMsg.asBuilder() .setQrFlag(true) .addAnswer(new Record<>(dnsQueryName, Record.TYPE.AAAA, 1, 64, new AAAA(Inet6Address.getByName(response).getAddress()))); handleDnsResponse(parsedPacket, builder.build().toArray()); return true; } } catch (Exception e) { Logger.logException(e); } return false; }
public InetAddress toInetAddress() throws UnknownHostException { return Inet6Address.getByName(toString()); }
public InetAddress toInetAddress() throws UnknownHostException { return Inet6Address.getByName(toString()); }
public InetAddress toInetAddress() throws UnknownHostException { return Inet6Address.getByName(toString()); }
/** * Returns the country the IP address is in. * * @param ipAddress String version of an IPv6 address, i.e. "::127.0.0.1" * @return the country the IP address is from. */ public Country getCountryV6(String ipAddress) { InetAddress addr; try { addr = Inet6Address.getByName(ipAddress); } catch (UnknownHostException e) { return UNKNOWN_COUNTRY; } return getCountryV6(addr); }
public static String resolveIPv6FromDomain(String domain) { if (domain == null) return null; if (isIPv6(domain)) { return domain; } try { String address = Inet6Address.getByName(domain).getHostAddress(); return isIPv6(address) ? address : null; } catch (UnknownHostException e) { log.info("Exception caught when resolving IPv6 address", e); } return null; }
.srcPort(UdpPort.DOMAIN) .dstPort(UdpPort.DOMAIN) .srcAddr((Inet6Address) Inet6Address.getByName("::0")) .dstAddr((Inet6Address) Inet6Address.getByName("::1")) .correctChecksumAtBuild(true) .correctLengthAtBuild(true) .flowLabel(IpV6SimpleFlowLabel.newInstance(0)) .nextHeader(IpNumber.UDP) .srcAddr((Inet6Address) Inet6Address.getByName("::0")) .dstAddr((Inet6Address) Inet6Address.getByName("::1")) .correctLengthAtBuild(true) .payloadBuilder(payLoadBuilder)