001: // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
002:
003: package org.xbill.DNS.tests;
004:
005: import java.util.*;
006: import org.xbill.DNS.*;
007:
008: public class xfrin {
009:
010: private static void usage(String s) {
011: System.out.println("Error: " + s);
012: System.out
013: .println("usage: xfrin [-i serial] [-k keyname/secret] "
014: + "[-s server] [-p port] [-f] zone");
015: System.exit(1);
016: }
017:
018: public static void main(String[] args) throws Exception {
019: ZoneTransferIn xfrin;
020: TSIG key = null;
021: int ixfr_serial = -1;
022: String server = null;
023: int port = SimpleResolver.DEFAULT_PORT;
024: boolean fallback = false;
025: Name zname;
026:
027: int arg = 0;
028: while (arg < args.length) {
029: if (args[arg].equals("-i")) {
030: ixfr_serial = Integer.parseInt(args[++arg]);
031: if (ixfr_serial < 0)
032: usage("invalid serial number");
033: } else if (args[arg].equals("-k")) {
034: String s = args[++arg];
035: int index = s.indexOf('/');
036: if (index < 0)
037: usage("invalid key");
038: key = new TSIG(s.substring(0, index), s
039: .substring(index + 1));
040: } else if (args[arg].equals("-s")) {
041: server = args[++arg];
042: } else if (args[arg].equals("-p")) {
043: port = Integer.parseInt(args[++arg]);
044: if (port < 0 || port > 0xFFFF)
045: usage("invalid port");
046: } else if (args[arg].equals("-f")) {
047: fallback = true;
048: } else if (args[arg].startsWith("-")) {
049: usage("invalid option");
050: } else {
051: break;
052: }
053: arg++;
054: }
055: if (arg >= args.length)
056: usage("no zone name specified");
057: zname = Name.fromString(args[arg]);
058:
059: if (server == null) {
060: Lookup l = new Lookup(zname, Type.NS);
061: Record[] ns = l.run();
062: if (ns == null) {
063: System.out.println("failed to look up NS record: "
064: + l.getErrorString());
065: System.exit(1);
066: }
067: server = ns[0].rdataToString();
068: System.out.println("sending to server '" + server + "'");
069: }
070:
071: if (ixfr_serial >= 0)
072: xfrin = ZoneTransferIn.newIXFR(zname, ixfr_serial,
073: fallback, server, port, key);
074: else
075: xfrin = ZoneTransferIn.newAXFR(zname, server, port, key);
076:
077: List response = xfrin.run();
078: if (xfrin.isAXFR()) {
079: if (ixfr_serial >= 0)
080: System.out.println("AXFR-like IXFR response");
081: else
082: System.out.println("AXFR response");
083: Iterator it = response.iterator();
084: while (it.hasNext())
085: System.out.println(it.next());
086: } else if (xfrin.isIXFR()) {
087: System.out.println("IXFR response");
088: Iterator it = response.iterator();
089: while (it.hasNext()) {
090: ZoneTransferIn.Delta delta;
091: delta = (ZoneTransferIn.Delta) it.next();
092: System.out.println("delta from " + delta.start + " to "
093: + delta.end);
094: System.out.println("deletes");
095: Iterator it2 = delta.deletes.iterator();
096: while (it2.hasNext())
097: System.out.println(it2.next());
098: System.out.println("adds");
099: it2 = delta.adds.iterator();
100: while (it2.hasNext())
101: System.out.println(it2.next());
102: }
103: } else if (xfrin.isCurrent()) {
104: System.out.println("up to date");
105: }
106: }
107:
108: }
|