下面列出了怎么用org.xbill.DNS.ZoneTransferException的API类实例代码及写法,或者点击链接到github查看源代码。
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;
}
public static void main(String[] args) {
if (args.length > 1) {
System.out.println("usage: jnamed [conf]");
System.exit(0);
}
try {
String conf;
if (args.length == 1) {
conf = args[0];
} else {
conf = "jnamed.conf";
}
new jnamed(conf);
} catch (IOException | ZoneTransferException e) {
System.out.println(e);
}
}
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;
}
public void addSecondaryZone(String zone, String remote)
throws IOException, ZoneTransferException {
Name zname = Name.fromString(zone, Name.root);
Zone newzone = new Zone(zname, DClass.IN, remote);
znames.put(zname, newzone);
}