当前位置: 首页>>代码示例>>Java>>正文


Java Resolver类代码示例

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


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

示例1: init

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

示例2: toRecord

import org.xbill.DNS.Resolver; //导入依赖的package包/类
/**
 * @param ip, like "192.168.1.1"
 * @return the complete DNS record for that IP.
 */
@Converter
public static Record toRecord(String ip) throws IOException {
    Resolver res = new ExtendedResolver();

    Name name = ReverseMap.fromAddress(ip);
    int type = Type.PTR;
    int dclass = DClass.IN;
    Record rec = Record.newRecord(name, type, dclass);
    Message query = Message.newQuery(rec);
    Message response = res.send(query);

    Record[] answers = response.getSectionArray(Section.ANSWER);
    if (answers.length == 0) {
        return null;
    } else {
        return answers[0];
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:DnsRecordConverter.java

示例3: resolveSrvByName

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

示例4: resolveHostByName

import org.xbill.DNS.Resolver; //导入依赖的package包/类
private String resolveHostByName(Resolver resolver, Name target) {
    Lookup lookup = new Lookup(target, A);
    if (resolver != null) {
        lookup.setResolver(resolver);
    }
    Record[] records = lookup.run();
    Optional<InetAddress> address = of(records)
            .filter(it -> it instanceof ARecord)
            .map(a -> ((ARecord) a).getAddress())
            .findFirst();
    if (address.isPresent()) {
        return address.get().getHostAddress();
    } else {
        log.warn("unknown name: " + target);
        return null;
    }
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:18,代码来源:DnsResolver.java

示例5: getResolvers

import org.xbill.DNS.Resolver; //导入依赖的package包/类
/**
 * Instantiate a set of default DNS <code>Resolver</code> by the provided Server. In case of
 * DNSSEC validation is needed, <code>ValidatingResolver</code> will be instantiated.
 *
 * @param dnsSec <code>true</code> iff DNSSEC is enabled
 * @param trustAnchor Public cryptographic to validate against
 *
 * @return A list of default <code>Resolver</code>
 *
 * @throws ConfigurationException
 *      Exceptional circumstances in which no default <code>Resolver</code> can be created.
 */
public static Map<String, Resolver> getResolvers(boolean dnsSec, String trustAnchor)
                                        throws ConfigurationException
{
    String[] servers = ResolverConfig.getCurrentConfig().servers();
    Map<String, Resolver> resolvers = new LinkedHashMap<>(servers.length);
    for (String server : servers) {
        Resolver resolver = instantiateResolver(dnsSec, trustAnchor, server);
        if (resolver != null) {
            resolvers.put(server, resolver);
        }
    }

    if (resolvers.isEmpty()) {
        throw new ConfigurationException("Unable to retrieve Default Resolvers");
    }

    return resolvers;
}
 
开发者ID:eclipse,项目名称:tiaki-java,代码行数:31,代码来源:DnsUtil.java

示例6: instantiateResolver

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

示例7: retrieveResolvers

import org.xbill.DNS.Resolver; //导入依赖的package包/类
/**
 * Private helper to retrieve a set of one or more instances of <code>Resolver</code> to carry
 * out the lookup.
 *
 * @param secValidation <code>true</code> iff DNSSEC validation id needed
 * @return Instance(s) of <code>Resolver</code>
 *
 * @throws ConfigurationException
 *      In case instance(s) of <code>Resolver</code> cannot he instantiated.
 */
private Map<String, Resolver> retrieveResolvers(boolean secValidation)
                                throws ConfigurationException
{
    Map<String, Resolver> resolvers = new LinkedHashMap<>();
    for(InetAddress dnsServer: this.dnsServers) {
        if (dnsServer != null && (!dnsServer.getHostAddress().isEmpty()
                || !dnsServer.getCanonicalHostName().isEmpty())) {
            String server = ((dnsServer.getHostAddress().isEmpty())
                    ? dnsServer.getCanonicalHostName() : dnsServer.getHostAddress());
            resolvers.put(server, DnsUtil.getResolver(secValidation, this.trustAnchorDefault, server));
        } else {
            resolvers.putAll(DnsUtil.getResolvers(secValidation, this.trustAnchorDefault));
        }
    }

    return resolvers;
}
 
开发者ID:eclipse,项目名称:tiaki-java,代码行数:28,代码来源:DnsServicesDiscovery.java

示例8: createResolver

import org.xbill.DNS.Resolver; //导入依赖的package包/类
private Resolver createResolver(String[] targets) throws IOException {
	// Shuffle input targets so we don't query the same all the time
	ArrayList<String> targetsList = new ArrayList<String>();
	for (String target : targets)
		targetsList.add(target);
	Collections.shuffle(targetsList);

	Resolver resolver = new ExtendedResolver(targetsList.toArray(new String[targetsList.size()]));
	resolver.setTimeout(RECURSIVE_QUERY_TIMEOUT);
	if (port != null)
		resolver.setPort(port);
	if (tcp != null)
		resolver.setTCP(tcp);
	if (ignoreTruncation != null)
		resolver.setIgnoreTruncation(ignoreTruncation);
	if (ednsLevel != null) {
		if (ednsPayloadSize != null && ednsFlags != null && ednsOptions != null)
			resolver.setEDNS(ednsLevel, ednsPayloadSize, ednsFlags, ednsOptions);
		else
			resolver.setEDNS(ednsLevel);
	}
	if (key != null)
		resolver.setTSIGKey(key);
	return resolver;
}
 
开发者ID:wnagele,项目名称:dnsjava-recursive-resolver,代码行数:26,代码来源:RecursiveResolver.java

示例9: setUp

import org.xbill.DNS.Resolver; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  lookupFactory = mock(LookupFactory.class);

  resolver = new XBillDnsSrvResolver(lookupFactory);

  xbillResolver = mock(Resolver.class);
}
 
开发者ID:spotify,项目名称:dns-java,代码行数:9,代码来源:XBillDnsSrvResolverTest.java

示例10: sendAdd

import org.xbill.DNS.Resolver; //导入依赖的package包/类
public boolean sendAdd() throws TextParseException, IOException
{
	boolean rc = false;
	
	Resolver res = createResolver();

	String revIp = buildReverseIpString();
	
	Name owner = new Name(revIp.toString());
	PTRRecord ptr = new PTRRecord(owner, DClass.IN, ttl, new Name(fqdn));
	
	Name _zone = buildZoneName(revIp);
	
	Update update = new Update(_zone);
	update.delete(owner);
	update.add(ptr);

	if (log.isDebugEnabled()) {
		log.debug("Sending reverse DDNS update (replace) to server=" + server + ":\n" + 
				update.toString());
	}
	else if (log.isInfoEnabled()) {
		log.info("Sending reverse DDNS update (replace): " + ptr.toString());
	}
	Message response = res.send(update);

	if (response.getRcode() == Rcode.NOERROR) {
		log.info("Reverse DDNS update (replace) succeeded: " + ptr.toString());
		rc = true;
	}
	else {
		log.error("Reverse DDNS update (replace) failed (rcode=" +
				Rcode.string(response.getRcode()) + "): " + ptr.toString());			
	}
	return rc;
}
 
开发者ID:jagornet,项目名称:dhcp,代码行数:37,代码来源:ReverseDdnsUpdate.java

示例11: ValidatingResolver

import org.xbill.DNS.Resolver; //导入依赖的package包/类
/**
 * Creates a new instance of this class.
 * 
 * @param headResolver The resolver to which queries for DS, DNSKEY and
 *            referring CNAME records are sent.
 */
public ValidatingResolver(Resolver headResolver) {
    this.headResolver = headResolver;
    headResolver.setEDNS(0, 0, ExtendedFlags.DO, null);
    headResolver.setIgnoreTruncation(false);

    this.keyCache = new KeyCache();
    this.valUtils = new ValUtils();
    this.n3valUtils = new NSEC3ValUtils();
    this.trustAnchors = new TrustAnchorStore();
}
 
开发者ID:ibauersachs,项目名称:dnssecjava,代码行数:17,代码来源:ValidatingResolver.java

示例12: DnsRequest

import org.xbill.DNS.Resolver; //导入依赖的package包/类
public DnsRequest(Message resp, Message req, Resolver res, long duration) {
	this.response = resp;
	this.request = req;
	this.resolver = res;
	this.duration = duration;
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:7,代码来源:Dig.java

示例13: getResolver

import org.xbill.DNS.Resolver; //导入依赖的package包/类
public Resolver getResolver() {
	return resolver;
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:4,代码来源:Dig.java

示例14: getResolver

import org.xbill.DNS.Resolver; //导入依赖的package包/类
public Resolver getResolver ()
   {
	return this.resolver;
}
 
开发者ID:eclipse,项目名称:tiaki-java,代码行数:5,代码来源:LookupContext.java

示例15: setResolver

import org.xbill.DNS.Resolver; //导入依赖的package包/类
public void setResolver ( Resolver resolver )
   {
	this.resolver = resolver;
}
 
开发者ID:eclipse,项目名称:tiaki-java,代码行数:5,代码来源:LookupContext.java


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