org.xbill.DNS.ResolverConfig Java Examples

The following examples show how to use org.xbill.DNS.ResolverConfig. 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: DNSFormActivity.java    From androdns with Apache License 2.0 6 votes vote down vote up
public String hostToAddr(String hostname) {
    if (hostname == null || hostname == "") {
        hostname = ResolverConfig.getCurrentConfig().server();
        if (hostname == null) {
            hostname = "0";
        }
    }
    InetAddress addr;
    try {
        if (hostname.equals("0"))
            addr = InetAddress.getLocalHost();
        else
            addr = InetAddress.getByName(hostname);
        InetSocketAddress address = new InetSocketAddress(addr, 53);
        return address.getAddress().getHostAddress();
    } catch (UnknownHostException e) {

    }
    return "";
}
 
Example #2
Source File: Output.java    From helios with Apache License 2.0 6 votes vote down vote up
public static String shortHostname(final String host) {
  final Name root = Name.fromConstantString(".");
  final Name hostname;
  try {
    hostname = Name.fromString(host, root);
  } catch (TextParseException e) {
    throw new IllegalArgumentException("Invalid hostname '" + host + "'");
  }

  final ResolverConfig currentConfig = ResolverConfig.getCurrentConfig();
  if (currentConfig != null) {
    final Name[] searchPath = currentConfig.searchPath();
    if (searchPath != null) {
      for (final Name domain : searchPath) {
        if (hostname.subdomain(domain)) {
          return hostname.relativize(domain).toString();
        }
      }
    }
  }
  return hostname.toString();
}
 
Example #3
Source File: SimpleDoTResolver.java    From androdns with Apache License 2.0 5 votes vote down vote up
public SimpleDoTResolver(String hostname, int port)throws UnknownHostException{
    if (hostname == null) {
        hostname = ResolverConfig.getCurrentConfig().server();
        if (hostname == null)
            hostname = defaultResolver;
    }
    InetAddress addr;
    if (hostname.equals("0"))
        addr = InetAddress.getLocalHost();
    else
        addr = InetAddress.getByName(hostname);
    address = new InetSocketAddress(addr, port);
}
 
Example #4
Source File: HostResolver.java    From helios with Apache License 2.0 5 votes vote down vote up
static HostResolver create(HeliosClient client) throws InterruptedException, ExecutionException {
  final ResolverConfig currentConfig = ResolverConfig.getCurrentConfig();
  final Name[] path;
  if (currentConfig != null) {
    final Name[] possiblePath = currentConfig.searchPath();
    if (possiblePath != null) {
      path = possiblePath;
    } else {
      path = EMPTY_PATH;
    }
  } else {
    path = EMPTY_PATH;
  }
  return new HostResolver(Sets.newHashSet(client.listHosts().get()), path);
}