本文整理匯總了Java中org.xbill.DNS.Lookup.getResult方法的典型用法代碼示例。如果您正苦於以下問題:Java Lookup.getResult方法的具體用法?Java Lookup.getResult怎麽用?Java Lookup.getResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.xbill.DNS.Lookup
的用法示例。
在下文中一共展示了Lookup.getResult方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
示例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: checkLookupStatus
import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
/**
* Validate the DNS <code>Lookup</code>, catching any transient or blocking issue.
*
* @param lookup A <code>Lookup</code> used to pull Resource Records
*
* @return A <code>StatusCode</code> with the check outcome
*
* @throws LookupException
* Containing the specific <code>StatusCode</code> defining the error that has been raised.
*/
public static StatusCode checkLookupStatus(Lookup lookup)
throws LookupException
{
StatusCode outcome = null;
if (lookup.getResult() == Lookup.TRY_AGAIN) {
outcome = StatusCode.NETWORK_ERROR;
} else if (lookup.getResult() == Lookup.UNRECOVERABLE) {
outcome = StatusCode.SERVER_ERROR;
} else if (lookup.getResult() == Lookup.HOST_NOT_FOUND) {
// Domain Name not found
outcome = StatusCode.RESOLUTION_NAME_ERROR;
} else if (lookup.getResult() == Lookup.TYPE_NOT_FOUND) {
// RR set not found
outcome = StatusCode.RESOLUTION_RR_TYPE_ERROR;
} else {
outcome = StatusCode.SUCCESSFUL_OPERATION;
}
return outcome;
}
示例5: 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()));
}
}
示例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: 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);
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: queryAddressRecords
import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
private Record[] queryAddressRecords(Name name) throws SendException {
Lookup lookup = new Lookup(name);
Record[] records = lookup.run();
switch (lookup.getResult()) {
case Lookup.SUCCESSFUL:
return records;
case Lookup.TYPE_NOT_FOUND:
throw new SendException("Host " + name + " has no address record ("
+ lookup.getErrorString() + ")",
EnhancedStatus.PERMANENT_UNABLE_TO_ROUTE);
case Lookup.HOST_NOT_FOUND:
throw new SendException("Host " + name + " is not found ("
+ lookup.getErrorString() + ")",
EnhancedStatus.PERMANENT_UNABLE_TO_ROUTE);
case Lookup.TRY_AGAIN:
throw new SendException(
"DNS network failure while looking up address of " + name
+ ": " + lookup.getErrorString(),
EnhancedStatus.TRANSIENT_DIRECTORY_SERVER_FAILURE);
case Lookup.UNRECOVERABLE:
throw new SendException(
"Unrecoverable DNS error while looking up address of "
+ name + ": " + lookup.getErrorString(),
EnhancedStatus.PERMANENT_UNABLE_TO_ROUTE);
default:
throw new SendException(
"Unknown DNS status while looking up address of " + name
+ ": " + lookup.getResult() + ". "
+ lookup.getErrorString(),
EnhancedStatus.PERMANENT_INTERNAL_ERROR);
}
}
示例12: testDnsJavaResponse
import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
@Test
public void testDnsJavaResponse() throws IOException {
final Lookup l = new Lookup("example.com");
final SimpleResolver resolver = new SimpleResolver("127.0.0.1");
resolver.setPort(9153);
l.setResolver(resolver);
l.run();
System.out.println("result: " + l.getResult());
if(l.getResult() == Lookup.SUCCESSFUL) {
System.out.println(l.getAnswers()[0].rdataToString());
}
assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}
示例13: testDnsJavaQuadARecord
import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
@Test
public void testDnsJavaQuadARecord() throws IOException {
final Lookup l = new Lookup("ipv6.example.com", Type.AAAA);
final SimpleResolver resolver = new SimpleResolver("::1");
resolver.setPort(9153);
l.setResolver(resolver);
l.run();
System.out.println("result: " + l.getResult());
if(l.getResult() == Lookup.SUCCESSFUL) {
System.out.println(l.getAnswers()[0].rdataToString());
}
assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}
示例14: lookup
import org.xbill.DNS.Lookup; //導入方法依賴的package包/類
/**
* Looks up DNS records of the specified type for the specified name.
*
* This method is a public wrapper for the private implementation method
*
* @param namestr
* the name of the host to be looked up
* @param type
* the type of record desired
* @param typeDesc
* the description of the record type, for debugging purpose
*/
protected Record[] lookup(String namestr, int type, String typeDesc) throws TemporaryResolutionException {
// Name name = null;
try {
// name = Name.fromString(namestr, Name.root);
Lookup l = new Lookup(namestr, type);
l.setCache(cache);
l.setResolver(resolver);
l.setCredibility(dnsCredibility);
l.setSearchPath(searchPaths);
Record[] r = l.run();
try {
if (l.getResult() == Lookup.TRY_AGAIN) {
throw new TemporaryResolutionException("DNSService is temporary not reachable");
} else {
return r;
}
} catch (IllegalStateException ise) {
// This is okay, because it mimics the original behaviour
// TODO find out if it's a bug in DNSJava
logger.debug("Error determining result ", ise);
throw new TemporaryResolutionException("DNSService is temporary not reachable");
}
// return rawDNSLookup(name, false, type, typeDesc);
} catch (TextParseException tpe) {
// TODO: Figure out how to handle this correctly.
logger.error("Couldn't parse name " + namestr, tpe);
return null;
}
}