當前位置: 首頁>>代碼示例>>Java>>正文


Java Lookup類代碼示例

本文整理匯總了Java中org.xbill.DNS.Lookup的典型用法代碼示例。如果您正苦於以下問題:Java Lookup類的具體用法?Java Lookup怎麽用?Java Lookup使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Lookup類屬於org.xbill.DNS包,在下文中一共展示了Lookup類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolve

import org.xbill.DNS.Lookup; //導入依賴的package包/類
public static String resolve(String host, int addrType) {
    try {
        Lookup lookup = new Lookup(host, addrType);
        SimpleResolver resolver = new SimpleResolver("114.114.114.114");
        resolver.setTimeout(5);
        lookup.setResolver(resolver);
        Record[] result = lookup.run();
        if (result == null) return null;

        List<Record> records = java.util.Arrays.asList(result);
        java.util.Collections.shuffle(records);
        for (Record record : records) {
            if (addrType == Type.A) {
                return ((ARecord) record).getAddress().getHostAddress();
            } else if (addrType == Type.AAAA) {
                return ((AAAARecord) record).getAddress().getHostAddress();
            }
        }

    } catch (Exception ex) {
        return null;
    }

    return null;
}
 
開發者ID:lparam,項目名稱:xTun-android,代碼行數:26,代碼來源:Utils.java

示例2: resolve

import org.xbill.DNS.Lookup; //導入依賴的package包/類
/**
 * Attempts to resolve an SMTP server address, given the destination e-mail address.
 *
 * @param email The e-mail address used for the lookup.
 * @return An optional, potentially containing
 */
protected Optional<String> resolve(String email) {
    Optional<String> domainOptional = extractDomain(email);

    if (!domainOptional.isPresent()) {
        return Optional.empty();
    }

    String mailDomain = domainOptional.get();

    try {
        Lookup dnsLookup = new Lookup(mailDomain, Type.MX);
        List<Record> records = Arrays.asList(dnsLookup.run());

        if (records.isEmpty()) {
            return Optional.empty();
        }

        return chooseBestRecord(records);

    } catch (TextParseException e) {
        e.printStackTrace();
    }

    return Optional.empty();
}
 
開發者ID:stevesoltys,項目名稱:carrier,代碼行數:32,代碼來源:MailResolverService.java

示例3: getUpdatedListOfServers

import org.xbill.DNS.Lookup; //導入依賴的package包/類
@Override
public List<ServiceCallServer> getUpdatedListOfServers(String name) {
    final Lookup lookup = lookupFactory.apply(name);
    final Record[] records = lookup.run();

    List<ServiceCallServer> servers;
    if (Objects.nonNull(records) && lookup.getResult() == Lookup.SUCCESSFUL) {
        servers = Arrays.stream(records)
            .filter(SRVRecord.class::isInstance)
            .map(SRVRecord.class::cast)
            .sorted(DnsServiceCallServer.COMPARATOR)
            .map(DnsServiceCallServer::new)
            .collect(Collectors.toList());
    } else {
        servers = Collections.emptyList();
    }

    return servers;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:20,代碼來源:DnsServiceCallServerListStrategies.java

示例4: reverseLookupByAddress

import org.xbill.DNS.Lookup; //導入依賴的package包/類
/**
 * reverse lookup an IP address using a specified DNS host and port
 *
 * @param resolverHost name server hostname or IP address
 * @param resolverPort name server port
 * @param address      the IP address to reverse lookup
 * @return a comma separated list of names or an empty string when unable to resolve
 */
public String reverseLookupByAddress(String resolverHost, int resolverPort, InetAddress address) {
    try {
        SimpleResolver resolver = new SimpleResolver(resolverHost);
        resolver.setPort(resolverPort);

        Lookup lookup = new Lookup(fromAddress(address), PTR);
        Record[] records = lookup.run();
        if (records != null) {
            List<String> addresses =
                    of(records)
                            .filter(it -> it instanceof PTRRecord)
                            .map(it -> ((PTRRecord) it).getTarget().toString())
                            .collect(toList());

            return collectionToCommaDelimitedString(addresses);
        } else {
            return "";
        }
    } catch (UnknownHostException e) {
        log.warn("unable to resolve using SRV record " + address, e);
        return "";
    }
}
 
開發者ID:amirkibbar,項目名稱:plum,代碼行數:32,代碼來源:DnsResolver.java

示例5: init

import org.xbill.DNS.Lookup; //導入依賴的package包/類
private void init() {
    if (mInitialized) return; else mInitialized = true;

    try {
        // configure the resolvers, starting with the default ones (based on the current network connection)
        Resolver defaultResolver = Lookup.getDefaultResolver();
        // use Google's public DNS services
        Resolver googleFirstResolver = new SimpleResolver("8.8.8.8");
        Resolver googleSecondResolver = new SimpleResolver("8.8.4.4");
        // also try using Amazon
        Resolver amazonResolver = new SimpleResolver("205.251.198.30");
        Lookup.setDefaultResolver(new ExtendedResolver(new Resolver[]{
                googleFirstResolver, googleSecondResolver, amazonResolver, defaultResolver }));
    } catch (UnknownHostException e) {
        Log.w(TAG, "Couldn't initialize custom resolvers");
    }
}
 
開發者ID:ov3rk1ll,項目名稱:KinoCast,代碼行數:18,代碼來源:CustomDns.java

示例6: testDnsJavaWithDnsServer

import org.xbill.DNS.Lookup; //導入依賴的package包/類
@Test
public void testDnsJavaWithDnsServer() throws TextParseException, UnknownHostException {
    final Lookup l = new Lookup("example.com", Type.AAAA);
    final SimpleResolver resolver = new SimpleResolver("::1");
    resolver.setPort(9153);
    l.setResolver(resolver);
    l.run();
    
    System.out.println("result: " + l.getResult());
    final Record[] answers = l.getAnswers();
    assertEquals(answers.length, 1);
    
    final Record record = answers[0];
    System.err.println(record.getTTL());
    
    if(l.getResult() == Lookup.SUCCESSFUL) {
        System.out.println(l.getAnswers()[0].rdataToString());
    }
    assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:21,代碼來源:DnsMonitorTest.java

示例7: reverseDNSLookup

import org.xbill.DNS.Lookup; //導入依賴的package包/類
public static String reverseDNSLookup(final InetAddress adr)
{
    try
    {
        final Name name = ReverseMap.fromAddress(adr);
        
        final Lookup lookup = new Lookup(name, Type.PTR);
        lookup.setResolver(new SimpleResolver());
        lookup.setCache(null);
        final Record[] records = lookup.run();
        if (lookup.getResult() == Lookup.SUCCESSFUL)
            for (final Record record : records)
                if (record instanceof PTRRecord)
                {
                    final PTRRecord ptr = (PTRRecord) record;
                    return ptr.getTarget().toString();
                }
    }
    catch (final Exception e)
    {
    }
    return null;
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:24,代碼來源:Helperfunctions.java

示例8: lookupSRVRecords

import org.xbill.DNS.Lookup; //導入依賴的package包/類
@Override
public List<SRVRecord> lookupSRVRecords(String name) throws TextParseException {
    List<SRVRecord> res = new ArrayList<SRVRecord>();

    Lookup lookup = new Lookup(name, Type.SRV);
    Record[] recs = lookup.run();
    if (recs == null)
        return res;

    for (Record record : recs) {
        org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record;
        if (srvRecord != null && srvRecord.getTarget() != null) {
            String host = srvRecord.getTarget().toString();
            int port = srvRecord.getPort();
            int priority = srvRecord.getPriority();
            int weight = srvRecord.getWeight();

            SRVRecord r = new SRVRecord(host, port, priority, weight);
            res.add(r);
        }
    }

    return res;
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:25,代碼來源:DNSJavaResolver.java

示例9: resolveHostByName

import org.xbill.DNS.Lookup; //導入依賴的package包/類
/**
 * resolves an A record by its name using a specified DNS host and port
 *
 * @param resolverHost name server hostname or IP address
 * @param resolverPort name server port
 * @param name         the DNS name of the A record - the name to resolve
 * @return a comma separated list of IP addresses or an empty string when unable to resolve
 */
public String resolveHostByName(String resolverHost, int resolverPort, String name) {
    try {
        SimpleResolver resolver = new SimpleResolver(resolverHost);
        resolver.setPort(resolverPort);

        Lookup lookup = new Lookup(name, A);
        Record[] records = lookup.run();
        if (records != null) {
            List<String> addresses =
                    of(records)
                            .filter(it -> it instanceof ARecord)
                            .map(it -> ((ARecord) it).getAddress().getHostAddress())
                            .collect(toList());

            return collectionToCommaDelimitedString(addresses);
        } else {
            return "";
        }
    } catch (UnknownHostException | TextParseException e) {
        log.warn("unable to resolve using A record " + name, e);
        return "";
    }
}
 
開發者ID:amirkibbar,項目名稱:plum,代碼行數:32,代碼來源:DnsResolver.java

示例10: resolveSrvByName

import org.xbill.DNS.Lookup; //導入依賴的package包/類
private String resolveSrvByName(Resolver resolver, String name) {
    try {
        Lookup lookup = new Lookup(name, SRV);
        if (resolver != null) {
            lookup.setResolver(resolver);
        }
        Record[] records = lookup.run();
        if (records == null) {
            return null;
        }

        return of(records)
                .filter(it -> it instanceof SRVRecord)
                .map(srv -> resolveHostByName(resolver, ((SRVRecord) srv).getTarget()) + ":" + ((SRVRecord) srv).getPort())
                .distinct()
                .collect(joining(","));
    } catch (TextParseException e) {
        log.warn("unable to resolve using SRV record " + name, e);
        return null;
    }
}
 
開發者ID:amirkibbar,項目名稱:plum,代碼行數:22,代碼來源:DnsResolver.java

示例11: checkLookupStatus

import org.xbill.DNS.Lookup; //導入依賴的package包/類
/**
 * Validate the DNS <code>Lookup</code>, catching any transient or blocking issue.
 *
 * @param lookup A <code>Lookup</code> used to pull Resource Records
 *
 * @return A <code>StatusCode</code> with the check outcome
 *
 * @throws LookupException
 *      Containing the specific <code>StatusCode</code> defining the error that has been raised.
 */
public static StatusCode checkLookupStatus(Lookup lookup)
        throws LookupException
{
    StatusCode outcome = null;
    if (lookup.getResult() == Lookup.TRY_AGAIN) {
        outcome = StatusCode.NETWORK_ERROR;
    } else if (lookup.getResult() == Lookup.UNRECOVERABLE) {
        outcome = StatusCode.SERVER_ERROR;
    } else if (lookup.getResult() == Lookup.HOST_NOT_FOUND) {
        // Domain Name not found
        outcome = StatusCode.RESOLUTION_NAME_ERROR;
    } else if (lookup.getResult() == Lookup.TYPE_NOT_FOUND) {
        // RR set not found
        outcome = StatusCode.RESOLUTION_RR_TYPE_ERROR;
    } else {
        outcome = StatusCode.SUCCESSFUL_OPERATION;
    }

    return outcome;
}
 
開發者ID:eclipse,項目名稱:tiaki-java,代碼行數:31,代碼來源:DnsUtil.java

示例12: resolve

import org.xbill.DNS.Lookup; //導入依賴的package包/類
@Override
public List<LookupResult> resolve(final String fqdn) {
  Lookup lookup = lookupFactory.forName(fqdn);
  Record[] queryResult = lookup.run();

  switch (lookup.getResult()) {
    case Lookup.SUCCESSFUL:
      return toLookupResults(queryResult);
    case Lookup.HOST_NOT_FOUND:
      // fallthrough
    case Lookup.TYPE_NOT_FOUND:
      LOG.warn("No results returned for query '{}'; result from XBill: {} - {}",
          fqdn, lookup.getResult(), lookup.getErrorString());
      return ImmutableList.of();
    default:
      throw new DnsException(
          String.format("Lookup of '%s' failed with code: %d - %s ",
              fqdn, lookup.getResult(), lookup.getErrorString()));
  }
}
 
開發者ID:spotify,項目名稱:dns-java,代碼行數:21,代碼來源:XBillDnsSrvResolver.java

示例13: testNoMxRecords

import org.xbill.DNS.Lookup; //導入依賴的package包/類
@Test()
public void testNoMxRecords() throws MxLookupException {
    new Expectations() {
        {
            lookup.run();
            result = null;

            lookup.getResult();
            result = Lookup.TYPE_NOT_FOUND;
        }

    };

    Name[] targets = mxLookup.queryMxTargets(EXAMPLE_COM_DOMAIN);
    assertArrayEquals(new Name[] { EXAMPLE_COM_NAME }, targets);
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:17,代碼來源:MxLookupTest.java

示例14: testTransientDnsFailure

import org.xbill.DNS.Lookup; //導入依賴的package包/類
@Test
public void testTransientDnsFailure() {
    new Expectations() {
        {
            lookup.run();
            result = null;

            lookup.getResult();
            result = Lookup.TRY_AGAIN;
        }
    };

    SendException e;
    try {
        addressLookup.queryAddresses(HOST1_EXAMPLE_COM_NAME);
        fail("An exception must have been thrown.");
        return;
    } catch (SendException e1) {
        e = e1;
    }

    assertTrue(e.errorStatus().shouldRetry());
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:24,代碼來源:AddressLookupTest.java

示例15: testNoAnswer

import org.xbill.DNS.Lookup; //導入依賴的package包/類
@Test
@JUnitDNSServer(port=9153, zones={})
public void testNoAnswer() throws Exception {
    final Lookup l = new Lookup("example.com", Type.AAAA);
    final SimpleResolver resolver = new SimpleResolver("::1");
    resolver.setPort(9153);
    l.setResolver(resolver);
    l.run();
    
    System.out.println("result: " + l.getResult());
    final Record[] answers = l.getAnswers();
    assertNotNull(answers);
    assertEquals(answers.length, 1);
    
    final Record record = answers[0];
    System.err.println(record.getTTL());
    
    if(l.getResult() == Lookup.SUCCESSFUL) {
        System.out.println(l.getAnswers()[0].rdataToString());
    }
    assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:23,代碼來源:DnsMonitorTest.java


注:本文中的org.xbill.DNS.Lookup類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。