Package org.xbill.DNS

Examples of org.xbill.DNS.Lookup


    };
  }

  public static List<URI> resolve(final String srvName, final String domain) {
    final String name = srv(srvName, domain);
    final Lookup lookup;
    try {
      lookup = new Lookup(name, Type.SRV, DClass.IN);
    } catch (TextParseException e) {
      throw new IllegalArgumentException("unable to create lookup for name: " + name, e);
    }

    Record[] queryResult = lookup.run();

    switch (lookup.getResult()) {
      case Lookup.SUCCESSFUL:
        final ImmutableList.Builder<URI> endpoints = ImmutableList.builder();
        for (Record record : queryResult) {
          if (record instanceof SRVRecord) {
            SRVRecord srv = (SRVRecord) record;
            endpoints.add(http(srv.getTarget().toString(), srv.getPort()));
          }
        }
        return endpoints.build();
      case Lookup.HOST_NOT_FOUND:
        // fallthrough
      case Lookup.TYPE_NOT_FOUND:
        log.warn("No results returned for query '{}'", name);
        return ImmutableList.of();
      default:
        throw new HeliosRuntimeException(String.format("Lookup of '%s' failed with code: %d - %s ",
                                                       name, lookup.getResult(),
                                                       lookup.getErrorString()));
    }
  }
View Full Code Here


      private Record[] lookupSrv(String query) throws TextParseException {
        while( true ) {
          try {
            // Bug 6427854 causes this to sometimes throw an NPE
            return new Lookup( query, Type.SRV ).run();
          } catch( NullPointerException npe ) {
            Thread.yield();
          }
        }
      }
View Full Code Here

        try {

            log.debug("Start "+recordTypeDescription+"-Record lookup for : " + request.getHostname());

            Lookup.getDefaultResolver().setTimeout(timeOut);
            Lookup query = new Lookup(request.getHostname(), dnsJavaType);

            Record[] rr = query.run();
            int queryResult = query.getResult();
           

            if (queryResult == Lookup.TRY_AGAIN) {
                throw new TimeoutException(query.getErrorString());
            }
           
            List records = convertRecordsToList(rr);
           
            log.debug("Found " + (rr != null ? rr.length : 0) + " "+recordTypeDescription+"-Records");
View Full Code Here

        // THIS WRITE a fully qualified MACHINE-NAME.MACHINE-DOMAIN
        System.out.println(InetAddress.getLocalHost().getCanonicalHostName());
        // THIS WRITE localhost
        System.out.println(InetAddress.getAllByName(null)[0]
                .getCanonicalHostName());
        Record[] record = new Lookup(Name.root, Type.ANY).run();
        if (record !=null) System.out.println(record[0]);
    }
View Full Code Here

      String scope = scopes[i];
      // remove dangling "."
      if(scope.endsWith(".")) { //$NON-NLS-1$
        scope = scope.substring(0, scope.length() - 1);
      }
      Lookup query;
      try {
        query = new Lookup(services[0] + "._udp" + "." + scope + ".", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            Type.PTR);
      } catch (TextParseException e) {
        continue;
      }
      result.add(query);
View Full Code Here

  protected Record[] getRecords(final DnsSdServiceTypeID serviceTypeId) {
    final List result = new ArrayList();
    final Lookup[] queries = serviceTypeId.getInternalQueries();
    for (int i = 0; i < queries.length; i++) {
      final Lookup query = queries[i];
      query.setResolver(resolver);
      final Record[] queryResult = query.run();
      if(queryResult != null) {
        result.addAll(Arrays.asList(queryResult));
      }
    }
    return (Record[]) result.toArray(new Record[result.size()]);
View Full Code Here

      Record[] srvQueryResult = null;
      final Record record = queryResult[j];
      if(record instanceof PTRRecord) {
        final PTRRecord ptrRecord = (PTRRecord) record;
        final Name target = ptrRecord.getTarget();
        final Lookup srvQuery = new Lookup(target, Type.SRV);
        srvQuery.setResolver(resolver);
        srvQueryResult = srvQuery.run();
      } else if (record instanceof SRVRecord) {
        srvQueryResult = new SRVRecord[]{(SRVRecord) record};
      } else {
        // avoid NPE
        srvQueryResult = new SRVRecord[0];
View Full Code Here

  }

  protected Collection getUpdateDomain(final Name zone) throws TextParseException {
    Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "getUpdateDomain(Name zone)", "Getting update domain"); //$NON-NLS-1$ //$NON-NLS-2$
    // query for special "_dns-update" SRV records which mark the server to use for dyndns
    final Lookup query = new Lookup(_DNS_UPDATE + zone, Type.SRV);
    // use the SRV record with the lowest priority/weight first
    final SortedSet srvRecords = getSRVRecord(query, new SRVRecordComparator());

    // if no dedicated "_dns-update" server is configured, fall back to regular authoritative server
    if(srvRecords.size() == 0) {
View Full Code Here

    Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "getAuthoritativeNameServer(Name zone)", "Trying to find authoritative name server"); //$NON-NLS-1$ //$NON-NLS-2$
    final Set result = new HashSet();
    final Name name = new Name(_DNS_UPDATE + zone);
   
    //query for NS records
    Lookup query = new Lookup(zone, Type.NS);
    query.setResolver(resolver);
    Record[] queryResult = query.run();
    //TODO file bug upstream that queryResult may never be null
    int length = queryResult == null ? 0 : queryResult.length;
    for (int j = 0; j < length; j++) {
      final Record record = queryResult[j];
      if(record instanceof NSRecord) {
        final NSRecord nsRecord = (NSRecord) record;
        final Name target = nsRecord.getTarget();
        result.add(new SRVRecord(name, DClass.IN, nsRecord.getTTL(), 0, 0, SimpleResolver.DEFAULT_PORT, target));
      }
    }
   
    //query for primary ns in SOA record (may overwrite/be equal to one of the ns records)
    query = new Lookup(zone, Type.SOA);
    query.setResolver(resolver);
    queryResult = query.run();
    //TODO file bug upstream that queryResult may never be null
    length = queryResult == null ? 0 : queryResult.length;
    for (int j = 0; j < length; j++) {
      final Record record = queryResult[j];
      if(record instanceof SOARecord) {
View Full Code Here

      // remove dangling "."
      if(scope.endsWith(".")) { //$NON-NLS-1$
        scope = scope.substring(0, scope.length() - 1);
      }
      for (int j = 0; j < protos.length; j++) {
        Lookup query;
        try {
          query = new Lookup(service + protos[j] + "." + scope + ".", //$NON-NLS-1$ //$NON-NLS-2$
              type);
        } catch (TextParseException e) {
          continue;
        }
        result.add(query);
View Full Code Here

TOP

Related Classes of org.xbill.DNS.Lookup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.