本文整理匯總了Java中org.xbill.DNS.Lookup.setResolver方法的典型用法代碼示例。如果您正苦於以下問題:Java Lookup.setResolver方法的具體用法?Java Lookup.setResolver怎麽用?Java Lookup.setResolver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.xbill.DNS.Lookup
的用法示例。
在下文中一共展示了Lookup.setResolver方法的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;
}
示例2: 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);
}
示例3: 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;
}
示例4: 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;
}
}
示例5: resolveHostByName
import org.xbill.DNS.Lookup; //導入方法依賴的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;
}
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: requestLookup
import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
/**
* Sends DNS request via system or custom DNS resolver
*/
private InetAddress[] requestLookup(String host) throws UnknownHostException {
InetAddress[] addresses = null;
if (isCustomResolver() && ((ExtendedResolver) resolver).getResolvers().length > 0) {
try {
Lookup lookup = new Lookup(host, Type.A);
lookup.setCache(lookupCache);
if (timeoutMs > 0) {
resolver.setTimeout(timeoutMs / 1000, timeoutMs % 1000);
}
lookup.setResolver(resolver);
Record[] records = lookup.run();
if (records == null || records.length == 0) {
throw new UnknownHostException("Failed to resolve host name: " + host);
}
addresses = new InetAddress[records.length];
for (int i = 0; i < records.length; i++) {
addresses[i] = ((ARecord) records[i]).getAddress();
}
} catch (TextParseException tpe) {
log.debug("Failed to create Lookup object: " + tpe);
}
} else {
addresses = systemDefaultDnsResolver.resolve(host);
if (log.isDebugEnabled()) {
log.debug("Cache miss: " + host + " Thread #" + JMeterContextService.getContext().getThreadNum()
+ ", resolved with system resolver into " + Arrays.toString(addresses));
}
}
return addresses;
}
示例13: buildLookup
import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
private Lookup buildLookup()
throws TextParseException, UnknownHostException {
ExtendedResolver resolver = new ExtendedResolver();
resolver.setTimeout(serviceDnsTimeout);
Lookup lookup = new Lookup(serviceDns, Type.SRV);
lookup.setResolver(resolver);
// Avoid caching temporary DNS lookup failures indefinitely in global cache
lookup.setCache(null);
return lookup;
}
示例14: main
import org.xbill.DNS.Lookup; //導入方法依賴的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);
}
}
示例15: doLookup
import org.xbill.DNS.Lookup; //導入方法依賴的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;
}