Package org.xbill.DNS

Examples of org.xbill.DNS.Lookup


            if(userDNSQuery){
              //�ؿ�ר��
              String email = mail.getRecipients(RecipientType.TO)[0].toString();
              String domain_name = parseDomain(email);
              //TODO: ʵ�������Ļ���,�ӿ�����ٶ�
              Lookup lookup = new Lookup(domain_name, Type.MX);
                  lookup.run();
              if (lookup.getResult() != Lookup.SUCCESSFUL){
                log("ERROR: " + lookup.getErrorString() + " when lookup MX record of " + email);
                continue;
              }
              Record[] answers = lookup.getAnswers();
              for(int ai=0;ai<answers.length;ai++){
                Transport transport = null;
                    log("Using " + answers[i].getAdditionalName()+" to send mail to " + email);
                    String mx_host = answers[i].getAdditionalName().toString();
                    mailSession.getProperties().put("mail.smtp.host", mx_host);
View Full Code Here


          mailMessage.setContent(multipart);
          mailMessage.setFrom(new InternetAddress("javayou@gmail.com","Winter Lau"));
         
          String mail_postfix = mailaddr.substring(mailaddr.indexOf('@')+1);
          //System.out.println("mail postfix is " + mail_postfix);
          Lookup lookup = new Lookup(mail_postfix, Type.MX);
          lookup.run();
      if (lookup.getResult() != Lookup.SUCCESSFUL){
        System.out.println(" " + lookup.getErrorString());
        return;
      }
      Record[] answers = lookup.getAnswers();
      for(int i=0;i<answers.length;i++){
            Transport transport = null;
            //System.out.println("Using " + answers[i].getAdditionalName()+" to send...");
            ssn.getProperties().put("mail.smtp.host", answers[i].getAdditionalName().toString());
            InternetAddress smtp_host = new InternetAddress(answers[i].getAdditionalName().toString());
View Full Code Here

  }

  public static void main(String[] args) throws Exception {
    int type = Type.MX;
    for (int i = 0; i < args.length; i++) {
      Lookup l = new Lookup(args[i], type);
      l.run();
      printAnswer(args[i], l);
      System.out.println("===============================");
    }
  }
View Full Code Here

        }
        try {

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

            Lookup query = new Lookup(request.getHostname(), dnsJavaType);
            query.setResolver(resolver);

            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

        try {

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

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

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

            if (queryResult == Lookup.TRY_AGAIN) {
                throw new TimeoutException();
            }
           
View Full Code Here

                            return protocolAddresses;
                        }

                        Lookup.setDefaultResolver(resolver);

                        final Lookup lookup;
                        try {
                            lookup = new Lookup(hostname);
                        } catch (TextParseException e) {
                            throw new UnknownHostException(hostname);
                        }

                        lookup.run();

                        if (lookup.getResult() == Lookup.SUCCESSFUL) {
                            final Record[] records = lookup.getAnswers();
                            final int recordCount = records.length;

                            protocolAddresses = new ProtocolAddress[recordCount];

                            for (int i = 0; i < recordCount; i++) {
                                final Record record = records[i];
                                protocolAddresses[i] = new IPv4Address(record.rdataToString());
                            }
                        } else {
                            throw new UnknownHostException(lookup.getErrorString());
                        }

                        return protocolAddresses;
                    }
                };
View Full Code Here

     */
    private MXRecord[] queryMxRecords() throws MxLookupException {
        org.xbill.DNS.Lookup lookup;

        try {
            lookup = new Lookup(domain.smtpText(), org.xbill.DNS.Type.MX);
        } catch (org.xbill.DNS.TextParseException e) {
            throw new MxLookupException(e,
                    EnhancedStatus.BAD_DESTINATION_MAILBOX_ADDRESS_SYNTAX);
        }

View Full Code Here

                return null;
            }
        }

        private String queryReason() {
            Lookup lookup;
            try {
                lookup = new Lookup(queryDomain, Type.TXT);
            } catch (TextParseException e) {
                throw new RuntimeException(e);
            }
            Record[] records = lookup.run();
            if (lookup.getResult() != Lookup.SUCCESSFUL
                    && lookup.getResult() != Lookup.TYPE_NOT_FOUND) {
                logger.warn("Error while looking up TXT record for "
                        + "address {} in DNSBL {}: {}", new Object[] { address,
                        domain, lookup.getErrorString() });
            }
            String reason = concatenateTxtRecordValues(records);
            return reason;
        }
View Full Code Here

        InetAddress[] addresses = convertAddressRecordsToAddresses(records);
        return addresses;
    }

    private Record[] queryAddressRecords() throws SendException {
        Lookup lookup = new Lookup(name);
        Record[] records = lookup.run();
        switch (lookup.getResult()) {
        case Lookup.SUCCESSFUL:
            return records;
        case Lookup.TYPE_NOT_FOUND:
            throw new SendException("Host " + name + " has no address record ("
                    + lookup.getErrorString() + ")",
                    EnhancedStatus.PERMANENT_UNABLE_TO_ROUTE, remoteMta);
        case Lookup.HOST_NOT_FOUND:
            throw new SendException("Host " + name + " is not found ("
                    + lookup.getErrorString() + ")",
                    EnhancedStatus.PERMANENT_UNABLE_TO_ROUTE, remoteMta);
        case Lookup.TRY_AGAIN:
            throw new SendException(
                    "DNS network failure while looking up address of " + name
                            + ": " + lookup.getErrorString(),
                    EnhancedStatus.TRANSIENT_DIRECTORY_SERVER_FAILURE,
                    remoteMta);
        case Lookup.UNRECOVERABLE:
            throw new SendException(
                    "Unrecoverable DNS error while looking up address of "
                            + name + ": " + lookup.getErrorString(),
                    EnhancedStatus.PERMANENT_UNABLE_TO_ROUTE, remoteMta);
        default:
            throw new SendException(
                    "Unknown DNS status while looking up address of " + name
                            + ": " + lookup.getResult() + ". "
                            + lookup.getErrorString(),
                    EnhancedStatus.PERMANENT_INTERNAL_ERROR, remoteMta);
        }
    }
View Full Code Here

  public 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(
              RemoteDelivery.SMTPScheme +
              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(RemoteDelivery.SMTPScheme + hostName));
        }
      }
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.