All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.couchbase.client.core.deps.org.xbill.DNS.tools.lookup Maven / Gradle / Ivy

There is a newer version: 3.7.2
Show newest version
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 1999-2004 Brian Wellington ([email protected])
package com.couchbase.client.core.deps.org.xbill.DNS.tools;

import com.couchbase.client.core.deps.org.xbill.DNS.Lookup;
import com.couchbase.client.core.deps.org.xbill.DNS.Name;
import com.couchbase.client.core.deps.org.xbill.DNS.Record;
import com.couchbase.client.core.deps.org.xbill.DNS.Type;

/** @author Brian Wellington <[email protected]> */
public class lookup {

  public static void printAnswer(String name, Lookup lookup) {
    System.out.print(name + ":");
    int result = lookup.getResult();
    if (result != Lookup.SUCCESSFUL) {
      System.out.print(" " + lookup.getErrorString());
    }
    System.out.println();
    Name[] aliases = lookup.getAliases();
    if (aliases.length > 0) {
      System.out.print("# aliases: ");
      for (int i = 0; i < aliases.length; i++) {
        System.out.print(aliases[i]);
        if (i < aliases.length - 1) {
          System.out.print(" ");
        }
      }
      System.out.println();
    }
    if (lookup.getResult() == Lookup.SUCCESSFUL) {
      Record[] answers = lookup.getAnswers();
      for (Record answer : answers) {
        System.out.println(answer);
      }
    }
  }

  public static void main(String[] args) throws Exception {
    int type = Type.A;
    int start = 0;
    if (args.length > 2 && args[0].equals("-t")) {
      type = Type.value(args[1]);
      if (type < 0) {
        throw new IllegalArgumentException("invalid type");
      }
      start = 2;
    }
    for (int i = start; i < args.length; i++) {
      Lookup l = new Lookup(args[i], type);
      l.run();
      printAnswer(args[i], l);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy