1 // Copyright (c) 1999-2004 Brian Wellington (bwelling (at) xbill.org) 2 3 package org.xbill.DNS.tests; 4 5 import java.util.*; 6 import org.xbill.DNS.*; 7 8 public class xfrin { 9 10 private static void 11 usage(String s) { 12 System.out.println("Error: " + s); 13 System.out.println("usage: xfrin [-i serial] [-k keyname/secret] " + 14 "[-s server] [-p port] [-f] zone"); 15 System.exit(1); 16 } 17 18 public static void 19 main(String [] args) throws Exception { 20 ZoneTransferIn xfrin; 21 TSIG key = null; 22 int ixfr_serial = -1; 23 String server = null; 24 int port = SimpleResolver.DEFAULT_PORT; 25 boolean fallback = false; 26 Name zname; 27 28 int arg = 0; 29 while (arg < args.length) { 30 if (args[arg].equals("-i")) { 31 ixfr_serial = Integer.parseInt(args[++arg]); 32 if (ixfr_serial < 0) 33 usage("invalid serial number"); 34 } else if (args[arg].equals("-k")) { 35 String s = args[++arg]; 36 int index = s.indexOf('/'); 37 if (index < 0) 38 usage("invalid key"); 39 key = new TSIG(s.substring(0, index), 40 s.substring(index+1)); 41 } else if (args[arg].equals("-s")) { 42 server = args[++arg]; 43 } else if (args[arg].equals("-p")) { 44 port = Integer.parseInt(args[++arg]); 45 if (port < 0 || port > 0xFFFF) 46 usage("invalid port"); 47 } else if (args[arg].equals("-f")) { 48 fallback = true; 49 } else if (args[arg].startsWith("-")) { 50 usage("invalid option"); 51 } else { 52 break; 53 } 54 arg++; 55 } 56 if (arg >= args.length) 57 usage("no zone name specified"); 58 zname = Name.fromString(args[arg]); 59 60 if (server == null) { 61 Lookup l = new Lookup(zname, Type.NS); 62 Record [] ns = l.run(); 63 if (ns == null) { 64 System.out.println("failed to look up NS record: " + 65 l.getErrorString()); 66 System.exit(1); 67 } 68 server = ns[0].rdataToString(); 69 System.out.println("sending to server '" + server + "'"); 70 } 71 72 if (ixfr_serial >= 0) 73 xfrin = ZoneTransferIn.newIXFR(zname, ixfr_serial, fallback, 74 server, port, key); 75 else 76 xfrin = ZoneTransferIn.newAXFR(zname, server, port, key); 77 78 List response = xfrin.run(); 79 if (xfrin.isAXFR()) { 80 if (ixfr_serial >= 0) 81 System.out.println("AXFR-like IXFR response"); 82 else 83 System.out.println("AXFR response"); 84 Iterator it = response.iterator(); 85 while (it.hasNext()) 86 System.out.println(it.next()); 87 } else if (xfrin.isIXFR()) { 88 System.out.println("IXFR response"); 89 Iterator it = response.iterator(); 90 while (it.hasNext()) { 91 ZoneTransferIn.Delta delta; 92 delta = (ZoneTransferIn.Delta) it.next(); 93 System.out.println("delta from " + delta.start + 94 " to " + delta.end); 95 System.out.println("deletes"); 96 Iterator it2 = delta.deletes.iterator(); 97 while (it2.hasNext()) 98 System.out.println(it2.next()); 99 System.out.println("adds"); 100 it2 = delta.adds.iterator(); 101 while (it2.hasNext()) 102 System.out.println(it2.next()); 103 } 104 } else if (xfrin.isCurrent()) { 105 System.out.println("up to date"); 106 } 107 } 108 109 } 110