org.xbill.DNS.AAAARecord Java Examples

The following examples show how to use org.xbill.DNS.AAAARecord. 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: AddressLookupTest.java    From mireka with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryAddressesIpv6() throws SendException {
    new Expectations() {
        {
            lookup.run();
            result =
                    new Record[] { new AAAARecord(HOST6_EXAMPLE_COM_NAME,
                            0, 0, IPV6)

                    };

        }
    };

    InetAddress[] addresses =
            addressLookup.queryAddresses(HOST1_EXAMPLE_COM_NAME);

    InetAddress[] expected = new InetAddress[] { IPV6 };
    assertArrayEquals(expected, addresses);
}
 
Example #2
Source File: ForwardLookupHelper.java    From yeti with MIT License 6 votes vote down vote up
public static List<ForwardLookupResult> getAAAARecord(String hostName, String domainName) throws TextParseException {
    List<ForwardLookupResult> entries = null;
    if (hostName != null && !hostName.isEmpty() && domainName != null && !domainName.isEmpty()) {
        Record[] recs = new Lookup(hostName, Type.AAAA).run();
        if (recs != null) {
            if (recs.length > 0) {
                entries = new ArrayList<>();
                for (Record record : recs) {
                    ForwardLookupResult foundSubDomain = new ForwardLookupResult(domainName);
                    foundSubDomain.setHostName(hostName);
                    String ipAddress = ((AAAARecord) record).getAddress().getHostAddress();
                    foundSubDomain.setIpAddress(ipAddress);
                    foundSubDomain.setLookupType("A");
                    entries.add(foundSubDomain);
                }
            }
        }
    }
    return entries;
}
 
Example #3
Source File: Utils.java    From ShadowsocksRR with Apache License 2.0 5 votes vote down vote up
public static String resolve(String host, int addrType) {
    try {
        Lookup lookup = new Lookup(host, addrType);
        SimpleResolver resolver = new SimpleResolver("114.114.114.114");
        resolver.setTimeout(5);
        lookup.setResolver(resolver);
        Record[] result = lookup.run();
        if (result == null || result.length == 0) {
            return null;
        }

        List<Record> records = new ArrayList<>(Arrays.asList(result));
        Collections.shuffle(records);
        for (Record r : records) {
            switch (addrType) {
                case Type.A:
                    return ((ARecord) r).getAddress().getHostAddress();
                case Type.AAAA:
                    return ((AAAARecord) r).getAddress().getHostAddress();
                default:
                    break;
            }
        }
    } catch (Exception e) {
        VayLog.e(TAG, "resolve", e);
        app.track(e);
    }
    return null;
}
 
Example #4
Source File: Utils.java    From Maying with Apache License 2.0 5 votes vote down vote up
public static String resolve(String host, int addrType) {
    try {
        Lookup lookup = new Lookup(host, addrType);
        SimpleResolver resolver = new SimpleResolver("114.114.114.114");
        resolver.setTimeout(5);
        lookup.setResolver(resolver);
        Record[] result = lookup.run();
        if (result == null || result.length == 0) {
            return null;
        }

        List<Record> records = new ArrayList<>(Arrays.asList(result));
        Collections.shuffle(records);
        for (Record r : records) {
            switch (addrType) {
                case Type.A:
                    return ((ARecord) r).getAddress().getHostAddress();
                case Type.AAAA:
                    return ((AAAARecord) r).getAddress().getHostAddress();
                default:
                    break;
            }
        }
    } catch (Exception e) {
        VayLog.e(TAG, "resolve", e);
        ShadowsocksApplication.app.track(e);
    }
    return null;
}
 
Example #5
Source File: DnsUpdateWriter.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private RRset makeV6AddressSet(HostResource host) {
  RRset addressSet = new RRset();
  for (InetAddress address : host.getInetAddresses()) {
    if (address instanceof Inet6Address) {
      AAAARecord record =
          new AAAARecord(
              toAbsoluteName(host.getHostName()),
              DClass.IN,
              dnsDefaultATtl.getStandardSeconds(),
              address);
      addressSet.addRR(record);
    }
  }
  return addressSet;
}
 
Example #6
Source File: AddressLookup.java    From mireka with Apache License 2.0 5 votes vote down vote up
private InetAddress[] convertAddressRecordsToAddresses(Record[] records) {
    InetAddress[] addresses = new InetAddress[records.length];
    for (int i = 0; i < records.length; i++) {
        Record record = records[i];
        if (record instanceof ARecord) {
            addresses[i] = ((ARecord) record).getAddress();
        } else if (record instanceof AAAARecord) {
            addresses[i] = ((AAAARecord) record).getAddress();
        } else {
            throw new RuntimeException();
        }
    }
    return addresses;
}