org.xbill.DNS.ZoneTransferIn Java Examples

The following examples show how to use org.xbill.DNS.ZoneTransferIn. 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: SimpleDoTResolver.java    From androdns with Apache License 2.0 6 votes vote down vote up
private Message
sendAXFR(Message query) throws IOException {
    Name qname = query.getQuestion().getName();
    ZoneTransferIn xfrin = ZoneTransferIn.newAXFR(qname, address, tsig);
    xfrin.setTimeout((int)(getTimeout() / 1000));
    xfrin.setLocalAddress(localAddress);
    try {
        xfrin.run();
    }
    catch (ZoneTransferException e) {
        throw new WireParseException(e.getMessage());
    }
    List records = xfrin.getAXFR();
    Message response = new Message(query.getHeader().getID());
    response.getHeader().setFlag(Flags.AA);
    response.getHeader().setFlag(Flags.QR);
    response.addRecord(query.getQuestion(), Section.QUESTION);
    Iterator it = records.iterator();
    while (it.hasNext())
        response.addRecord((Record)it.next(), Section.ANSWER);
    return response;
}
 
Example #2
Source File: ForwardLookupHelper.java    From yeti with MIT License 5 votes vote down vote up
public static List<ForwardLookupResult> attemptZoneTransfer(String domain, List<ForwardLookupResult> nameServers) throws TextParseException {
    List<ForwardLookupResult> result = new ArrayList<>();

    ZoneTransferIn xfr;
    Iterator i = nameServers.iterator();
    for (ForwardLookupResult nameServer : nameServers) {
        try {
            xfr = ZoneTransferIn.newAXFR(new Name(domain), nameServer.getIpAddress(), null);
            List records = xfr.run();
            for (Iterator it = records.iterator(); it.hasNext();) {
                Record r = (Record) it.next();
                if (r.getType() == 1) {
                    ForwardLookupResult rec = new ForwardLookupResult(domain);
                    String hostName = ((ARecord) r).getName().toString().toLowerCase();

                    if (hostName.endsWith(".")) {
                        hostName = hostName.substring(0, hostName.length() - 1);
                    }

                    rec.setHostName(hostName);
                    rec.setIpAddress(((ARecord) r).getAddress().getHostAddress());
                    rec.setLookupType("A");
                    result.add(rec);
                }
            }
        } catch (IOException ioex) {
            Logger.getLogger("ForwardLookupHelper.attemptZoneTransfer").log(Level.WARNING, null, ioex);
        } catch (ZoneTransferException zex) {
            Log.debug("ForwardLookupHelper.attemptZoneTransfer: Failed zonetransfer");
        }
    }
    return result;
}