本文整理汇总了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");
}
}
示例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];
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例13: getResolver
import org.xbill.DNS.Resolver; //导入依赖的package包/类
public Resolver getResolver() {
return resolver;
}
示例14: getResolver
import org.xbill.DNS.Resolver; //导入依赖的package包/类
public Resolver getResolver ()
{
return this.resolver;
}
示例15: setResolver
import org.xbill.DNS.Resolver; //导入依赖的package包/类
public void setResolver ( Resolver resolver )
{
this.resolver = resolver;
}