Package org.xbill.DNS

Examples of org.xbill.DNS.Lookup


    }

    public List<ResolvedAddress> resolveXmppServer(String domain) {
        List<ResolvedAddress> addresses = new ArrayList<ResolvedAddress>();
        try {
            Record[] records = new Lookup("_xmpp-server._tcp." + domain, Type.SRV).run();
            if(records != null) {
                for (int i = 0; i < records.length; i++) {
                    SRVRecord srv = (SRVRecord) records[i];
                    addresses.add(new ResolvedAddress(srv.getTarget(), srv.getPort(), srv.getPriority()));
                }
View Full Code Here


                Integer dnsClass = null;
                if (dclass != null) {
                    dnsClass = DClass.value(String.valueOf(dclass));
                }

                Lookup lookup;
                if (dnsType != null && dnsClass != null) {
                    lookup = new Lookup(dnsName, dnsType, dnsClass);
                } else {
                    if (dnsType != null) {
                        lookup = new Lookup(dnsName, dnsType);
                    } else {
                        lookup = new Lookup(dnsName);
                    }
                }

                lookup.run();
                if (lookup.getAnswers() != null) {
                    exchange.getOut().setBody(lookup.getAnswers());
                } else {
                    exchange.getOut().setBody(lookup.getErrorString());
                }
            }
        };
    }
View Full Code Here

  public static void main(String[] args) throws Exception {
    int type = Type.A;
    String domainName = "www.twitter.com";
    for (int i = 0; i < 1; i++) {
      Thread.sleep(200);
      Lookup l = new Lookup(domainName, type);
      l.run();
      recordAnswer(domainName, l);
    }
  }
View Full Code Here

        // domain need to be fully qualified with new dnsjava version
        if (domainNameToLookup.charAt(domainNameToLookup.length() - 1) != '.') {
            domainNameToLookup += ".";
        }

        Lookup lkup = null;

        try {
            lkup = new Lookup(domainNameToLookup, type);
        } catch (TextParseException e) {
            // we wants only one "checked" exception, lets wrap into a
            // DnsLookupFailedException
            throw new DnsLookupFailedException("Failed to lookup domain:" +
                domainNameToLookup + " error:" + e.getMessage());
        }

        Record[] records = lkup.run();
        int res = lkup.getResult();

        if (res == Lookup.TRY_AGAIN) {
            throw new DnsServerUnavailableException(lkup.getErrorString());
        } else if (lkup.getResult() != Lookup.SUCCESSFUL) {
            throw new DnsLookupFailedException("no such domain:" +
                domainNameToLookup + " error:" + lkup.getErrorString());
        }

        return records;
    }
View Full Code Here

                Integer dnsClass = null;
                if (dclass != null) {
                    dnsClass = DClass.value(String.valueOf(dclass));
                }

                Lookup lookup = (dnsClass == null)
                    ? (dnsType == null ? new Lookup(dnsName) : new Lookup(dnsName, dnsType))
                        : new Lookup(dnsName, dnsType, dnsClass);

                lookup.run();
                if (lookup.getAnswers() != null) {
                    exchange.getIn().setBody(lookup.getAnswers());
                } else {
                    throw new CamelException(lookup.getErrorString());
                }
            }
        };
    }
View Full Code Here

     */
    protected Record[] lookup(String namestr, int type, String typeDesc) throws TemporaryResolutionException {
        // Name name = null;
        try {
            // name = Name.fromString(namestr, Name.root);
            Lookup l = new Lookup(namestr, type);
           
            l.setCache(cache);
            l.setResolver(resolver);
            l.setCredibility(dnsCredibility);
            l.setSearchPath(searchPaths);
            Record[] r = l.run();
           
            try {
                if (l.getResult() == Lookup.TRY_AGAIN) {
                    throw new TemporaryResolutionException(
                            "DNSService is temporary not reachable");
                } else {
                    return r;
                }
View Full Code Here

  public static Collection<URLName> getMXRecordsForHost(String hostName) {

    Vector<URLName> recordsColl = null;
    try {
      boolean foundOriginalMX = true;
      Record[] records = new Lookup(hostName, Type.MX).run();
     
      /*
       * Sometimes we should send an email to a subdomain which does not
       * have own MX record and MX server. At this point we should find an
       * upper level domain and server where we can deliver our email.
       * 
       * Example: subA.subB.domain.name has not own MX record and
       * subB.domain.name is the mail exchange master of the subA domain
       * too.
       */
      if( records == null || records.length == 0 )
      {
        foundOriginalMX = false;
        String upperLevelHostName = hostName;
        while(    records == null &&
              upperLevelHostName.indexOf(".") != upperLevelHostName.lastIndexOf(".") &&
              upperLevelHostName.lastIndexOf(".") != -1
          )
        {
          upperLevelHostName = upperLevelHostName.substring(upperLevelHostName.indexOf(".")+1);
          records = new Lookup(upperLevelHostName, Type.MX).run();
        }
      }

            if( records != null )
            {
              // Sort in MX priority (higher number is lower priority)
                Arrays.sort(records, new Comparator<Record>() {
                    @Override
                    public int compare(Record arg0, Record arg1) {
                        return ((MXRecord)arg0).getPriority()-((MXRecord)arg1).getPriority();
                    }
                });
                // Create records collection
                recordsColl = new Vector<URLName>(records.length);
                for (int i = 0; i < records.length; i++)
        {
          MXRecord mx = (MXRecord) records[i];
          String targetString = mx.getTarget().toString();
          URLName uName = new URLName(
              SMTP_PROTOCOL_PREFIX +
              targetString.substring(0, targetString.length() - 1)
          );
          recordsColl.add(uName);
        }
            }else
            {
              foundOriginalMX = false;
              recordsColl = new Vector<URLName>();
            }
           
            /*
             * If we found no MX record for the original hostname (the upper
             * level domains does not matter), then we add the original domain
             * name (identified with an A record) to the record collection,
             * because the mail exchange server could be the main server too.
       *
       * We append the A record to the first place of the record
       * collection, because the standard says if no MX record found then
       * we should to try send email to the server identified by the A
       * record.
             */
      if( !foundOriginalMX )
      {
        Record[] recordsTypeA = new Lookup(hostName, Type.A).run();
        if (recordsTypeA != null && recordsTypeA.length > 0)
        {
          recordsColl.add(0, new URLName(SMTP_PROTOCOL_PREFIX + hostName));
        }
      }
View Full Code Here

    // MX records fetching
    getMXRecord(domain);
  }
 
  private static void getMXRecord(String name) throws TextParseException, UnknownHostException {
    Lookup lookup = new Lookup(name, Type.MX);
    Resolver resolver = new SimpleResolver();
//    lookup.setResolver(resolver);
//    lookup.setCache(null);
    for (Record dnsRecord: lookup.run()) {
      MXRecord record = (MXRecord)dnsRecord;
      System.out.println(record.getPriority() + " " + record.rdataToString());
    }
  }
View Full Code Here

    try {
      Resolver resolver = (this.nameserver==null) ? new SimpleResolver() : new SimpleResolver(this.nameserver);

      // try to lookup the MX records
      Lookup lookup = new Lookup(atHost,Type.MX);
      lookup.setResolver(resolver);
      lookup.run();
      Record[] records = lookup.getAnswers();
      if ( records == null ) {
        // in the event there are no MX records, then punt and try to find A record
        Lookup lookup2 = new Lookup(atHost,Type.A);
        lookup2.setResolver(resolver);
        lookup2.run();
        records = lookup2.getAnswers();
        if ( records == null ) {
          // the caller will have to check for an empty result and decide not to put it in the cache.
          return new MXLookupResult(null);
        }
      }
View Full Code Here

            throws TempFailException, PermFailException {
        if (!"dns/txt".equals(methodAndOptions))
            throw new PermFailException("Only dns/txt is supported: "
                    + methodAndOptions + " options unsupported.");
        try {
            Lookup query = new Lookup(selector + "._domainkey." + token,
                    Type.TXT);
            query.setResolver(resolver);

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

            if (queryResult == Lookup.TRY_AGAIN) {
                throw new TempFailException(query.getErrorString());
            }

            List<String> records = convertRecordsToList(rr);
            return records;
        } catch (TextParseException e) {
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.