• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SimpleResolver类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.xbill.DNS.SimpleResolver的典型用法代码示例。如果您正苦于以下问题:Java SimpleResolver类的具体用法?Java SimpleResolver怎么用?Java SimpleResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SimpleResolver类属于org.xbill.DNS包,在下文中一共展示了SimpleResolver类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: resolve

import org.xbill.DNS.SimpleResolver; //导入依赖的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: reverseLookupByAddress

import org.xbill.DNS.SimpleResolver; //导入依赖的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


示例3: init

import org.xbill.DNS.SimpleResolver; //导入依赖的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


示例4: testDnsJavaWithDnsServer

import org.xbill.DNS.SimpleResolver; //导入依赖的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.SimpleResolver; //导入依赖的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: resolveHostByName

import org.xbill.DNS.SimpleResolver; //导入依赖的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


示例7: instantiateResolver

import org.xbill.DNS.SimpleResolver; //导入依赖的package包/类
/**
 * Private helper to instantiate a DNS <code>Resolver</code> by the provided Server.
 *
 * @param dnsSec <code>true</code> iff DNSSEC is enabled
 * @param trustAnchor Public cryptographic to validate against
 * @param server Server to use as DNS resolver
 *
 * @return <code>null</code> in case the <code>Resolver</code> cannot be instantiated
 */
private static Resolver instantiateResolver(boolean dnsSec, String trustAnchor, String server)
{
    try {
        Resolver resolver = new SimpleResolver(server);
        if (!dnsSec) {
            return resolver;
        }

        ValidatingResolver validating = new ValidatingResolver(resolver);
        validating.loadTrustAnchors(new ByteArrayInputStream(trustAnchor.getBytes(StandardCharsets.UTF_8)));

        return validating;
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:eclipse,项目名称:tiaki-java,代码行数:26,代码来源:DnsUtil.java


示例8: testNoAnswer

import org.xbill.DNS.SimpleResolver; //导入依赖的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


示例9: testNoAnswer

import org.xbill.DNS.SimpleResolver; //导入依赖的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


示例10: getASN

import org.xbill.DNS.SimpleResolver; //导入依赖的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


示例11: getASName

import org.xbill.DNS.SimpleResolver; //导入依赖的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


示例12: getAScountry

import org.xbill.DNS.SimpleResolver; //导入依赖的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


示例13: process

import org.xbill.DNS.SimpleResolver; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
    String server = exchange.getIn().getHeader(DnsConstants.DNS_SERVER, String.class);

    SimpleResolver resolver = new SimpleResolver(server);
    int type = Type.value(exchange.getIn().getHeader(DnsConstants.DNS_TYPE, String.class));
    if (type == -1) {
        // default: if unparsable value given, use A.
        type = Type.A;
    }

    String dclassValue = exchange.getIn().getHeader(DnsConstants.DNS_CLASS, String.class);
    if (dclassValue == null) {
        dclassValue = "";
    }

    int dclass = DClass.value(dclassValue);
    if (dclass == -1) {
        // by default, value is IN.
        dclass = DClass.IN;
    }

    Name name = Name.fromString(exchange.getIn().getHeader(DnsConstants.DNS_NAME, String.class), Name.root);
    Record rec = Record.newRecord(name, type, dclass);
    Message query = Message.newQuery(rec);
    Message response = resolver.send(query);
    exchange.getIn().setBody(response);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:DnsDigProducer.java


示例14: process

import org.xbill.DNS.SimpleResolver; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
    SimpleResolver resolver = new SimpleResolver();
    int type = Type.TXT;
    Name name = Name.fromString(String.valueOf(exchange.getIn().getHeader(DnsConstants.TERM)) + ".wp.dg.cx", Name.root);
    Record rec = Record.newRecord(name, type, DClass.IN);
    Message query = Message.newQuery(rec);
    Message response = resolver.send(query);
    Record[] records = response.getSectionArray(Section.ANSWER);
    if (records.length > 0) {
        exchange.getIn().setBody(records[0].rdataToString());
    } else {
        exchange.getIn().setBody(null);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:DnsWikipediaProducer.java


示例15: resolveTextByName

import org.xbill.DNS.SimpleResolver; //导入依赖的package包/类
/**
 * resolves the TXT field for a given name using a specified DNS host and port. This is useful, for example,
 * if you want to resolve abusers with: <a href="https://abusix.com/contactdb.html">https://abusix.com/contactdb.html</a>
 *
 * @param resolverHost name server hostname or IP address
 * @param resolverPort name server port
 * @param name         the DNS name of the TXT record - the name to resolve
 * @return the resolved text
 */
public String resolveTextByName(String resolverHost, int resolverPort, String name) {
    try {
        SimpleResolver resolver = new SimpleResolver(resolverHost);
        resolver.setPort(resolverPort);

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

            return collectionToCommaDelimitedString(addresses);
        } else {
            return "";
        }
    } catch (UnknownHostException | TextParseException e) {
        log.warn("unable to resolve using TXT record " + name, e);
        return "";
    }
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:33,代码来源:DnsResolver.java


示例16: resolveServiceByName

import org.xbill.DNS.SimpleResolver; //导入依赖的package包/类
/**
 * resolves an SRV 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 SRV record
 * @return a comma separate list of ip:port, e.g: 1.2.3.4:8080,2.3.4.5:9090 or null when unable to resolve
 */
public String resolveServiceByName(String resolverHost, int resolverPort, String name) {
    try {
        SimpleResolver resolver = new SimpleResolver(resolverHost);
        resolver.setPort(resolverPort);

        return resolveSrvByName(resolver, name);
    } catch (UnknownHostException e) {
        log.warn("unable to resolve using SRV record " + name, e);
        return null;
    }
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:20,代码来源:DnsResolver.java


示例17: main

import org.xbill.DNS.SimpleResolver; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	Lookup lookup = new Lookup("www.xqbase.com");
	lookup.setResolver(new SimpleResolver("localhost"));
	lookup.run();
	for (Record record : lookup.getAnswers()) {
		System.out.println(record);
	}
}
 
开发者ID:xqbase,项目名称:ddns,代码行数:9,代码来源:TestLookup.java


示例18: getResolver

import org.xbill.DNS.SimpleResolver; //导入依赖的package包/类
private SimpleResolver getResolver() throws UnknownHostException {
  final String skyDnsAddress = getEnv("SKYDNS_SERVER", "localhost");
  final SimpleResolver resolver = new SimpleResolver(skyDnsAddress);
  final String skyDnsPort = System.getenv("SKYDNS_PORT");
  resolver.setPort(isNullOrEmpty(skyDnsPort) ? 53 : Integer.parseInt(skyDnsPort));
  return resolver;
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:8,代码来源:UsingSkyDnsITCase.java


示例19: doLookup

import org.xbill.DNS.SimpleResolver; //导入依赖的package包/类
private Lookup doLookup(final SimpleResolver resolver, String hostname)
    throws TextParseException {
  final Cache cache = new Cache();
  final Lookup lookup = new Lookup(new Name(hostname), org.xbill.DNS.Type.SRV);
  lookup.setResolver(resolver);
  lookup.setCache(cache);
  return lookup;
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:9,代码来源:UsingSkyDnsITCase.java


示例20: canResolveRecord

import org.xbill.DNS.SimpleResolver; //导入依赖的package包/类
@Test
public void canResolveRecord() throws Exception {
    AcceptanceTestRunner runner = new AcceptanceTestRunner();
    runner.runUngarded(new AcceptanceScenario() {

        public void run(WebDriver driver, String deployedURL) throws Exception {
            int id = new SecureRandom().nextInt();
            final String systemTestBase = "system-tests.onomate.test";
            final String soaBase = "soa-" + id +"."+ systemTestBase;
            final String ns = "ns." + soaBase;
            final String contactName = "admin." + soaBase;
            final String aTestRecordHost = "record."+soaBase;
            final String aTestRecordNS = "ns.test";

            OnomateAssembly assembly = new OnomateAssembly(driver, deployedURL);
            OnomateAssembly.Dashboard board = assembly.gotoLanding().authenticate().newAuthority(soaBase, ns, contactName);
            board.authorityByZone(soaBase).details().createRecord(aTestRecordHost, OnomateAssembly.RecordType.NS, aTestRecordNS);

            Options.set("verbose");
            
            SimpleResolver resolver = new SimpleResolver();
            resolver.setAddress(InetAddress.getLocalHost());
            resolver.setPort(9101);
            
            Record query = Record.newRecord(Name.fromString(aTestRecordHost + "."), Type.NS, DClass.IN);
            Message question = Message.newQuery(query);
            Message response = resolver.send(question);
            Record responses[] = response.getSectionArray(Section.AUTHORITY);
            NSRecord record = ((NSRecord) responses[0]);
            assertEquals(record.getName().toString(), aTestRecordHost+ ".");
            assertEquals(record.getTarget().toString(), aTestRecordNS + ".");
        }
    });
}
 
开发者ID:meschbach,项目名称:onomate,代码行数:35,代码来源:CreateNSRecordTests.java



注:本文中的org.xbill.DNS.SimpleResolver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AntlrProposalConflictHelper类代码示例发布时间:2022-05-21
下一篇:
Java HttpVersion类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap