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


Java Lookup.run方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: testDNameWithNoCnameIsValid

import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
@Test
public void testDNameWithNoCnameIsValid() throws IOException {
    Message m = resolver.send(createMessage("www.isc.ingotronic.ch./A"));
    Message message = messageFromString(m.toString().replaceAll("(.*CNAME.*)", "").replaceAll("\n\n", "\n"));
    add("www.isc.ingotronic.ch./A", message);

    Message response = resolver.send(createMessage("www.isc.ingotronic.ch./A"));
    assertTrue("AD flag must be set", response.getHeader().getFlag(Flags.AD));
    assertEquals(Rcode.NOERROR, response.getRcode());
    assertNull(getReason(response));
    Lookup l = new Lookup("www.isc.ingotronic.ch");
    l.setResolver(resolver);
    Record[] results = l.run();
    assertTrue(results != null);
    assertTrue(results.length >= 1);
}
 
開發者ID:ibauersachs,項目名稱:dnssecjava,代碼行數:17,代碼來源:TestDNames.java

示例12: 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();
    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:vishwaabhinav,項目名稱:OpenNMS,代碼行數:22,代碼來源:DnsMonitorTest.java

示例13: getASN

import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
public static Long getASN(final InetAddress adr)
{
    try
    {
        final Name postfix;
        if (adr instanceof Inet6Address)
            postfix = Name.fromConstantString("origin6.asn.cymru.com");
        else
            postfix = Name.fromConstantString("origin.asn.cymru.com");
        
        final Name name = getReverseIPName(adr, postfix);
        System.out.println("lookup: " + name);
        
        final Lookup lookup = new Lookup(name, Type.TXT);
        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 TXTRecord)
                {
                    final TXTRecord txt = (TXTRecord) record;
                    @SuppressWarnings("unchecked")
                    final List<String> strings = txt.getStrings();
                    if (strings != null && !strings.isEmpty())
                    {
                        final String result = strings.get(0);
                        final String[] parts = result.split(" ?\\| ?");
                        if (parts != null && parts.length >= 1)
                            return new Long(parts[0].split(" ")[0]);
                    }
                }
    }
    catch (final Exception e)
    {
    }
    return null;
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:39,代碼來源:Helperfunctions.java

示例14: getASName

import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
public static String getASName(final long asn)
{
    try
    {
        final Name postfix = Name.fromConstantString("asn.cymru.com.");
        final Name name = new Name(String.format("AS%d", asn), postfix);
        System.out.println("lookup: " + name);
        
        final Lookup lookup = new Lookup(name, Type.TXT);
        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 TXTRecord)
                {
                    final TXTRecord txt = (TXTRecord) record;
                    @SuppressWarnings("unchecked")
                    final List<String> strings = txt.getStrings();
                    if (strings != null && !strings.isEmpty())
                    {
                        System.out.println(strings);
                        
                        final String result = strings.get(0);
                        final String[] parts = result.split(" ?\\| ?");
                        if (parts != null && parts.length >= 1)
                            return parts[4];
                    }
                }
    }
    catch (final Exception e)
    {
    }
    return null;
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:36,代碼來源:Helperfunctions.java

示例15: getAScountry

import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
public static String getAScountry(final long asn)
{
    try
    {
        final Name postfix = Name.fromConstantString("asn.cymru.com.");
        final Name name = new Name(String.format("AS%d", asn), postfix);
        System.out.println("lookup: " + name);
        
        final Lookup lookup = new Lookup(name, Type.TXT);
        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 TXTRecord)
                {
                    final TXTRecord txt = (TXTRecord) record;
                    @SuppressWarnings("unchecked")
                    final List<String> strings = txt.getStrings();
                    if (strings != null && !strings.isEmpty())
                    {
                        final String result = strings.get(0);
                        final String[] parts = result.split(" ?\\| ?");
                        if (parts != null && parts.length >= 1)
                            return parts[1];
                    }
                }
    }
    catch (final Exception e)
    {
    }
    return null;
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:34,代碼來源:Helperfunctions.java


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