Package org.xbill.DNS
Class Lookup
java.lang.Object
org.xbill.DNS.Lookup
The Lookup object issues queries to the local hosts database (
/etc/hosts) and to
recursive DNS servers. The input consists of a name, an optional type, and an optional class.
Caching is enabled by default and used when possible to reduce the number of DNS requests. A
Resolver, which defaults to an ExtendedResolver initialized with the resolvers
located by the ResolverConfig class, performs the queries. A search path of domain
suffixes is used to resolve relative names, and is also determined by the ResolverConfig
class.
A Lookup object may be reused, but should not be used by multiple threads.
Lookup is considered legacy (but not yet deprecated). Use LookupSession instead, which is thread safe and fully async.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Record[]private booleanprivate Stringprivate Cacheprivate intprivate booleanprivate final intprivate static HostsFileParserprivate static intprivate static Resolverprivate booleanprivate booleanprivate Stringprivate booleanstatic final intThe host does not exist.private HostsFileParserGets or sets the local hosts database parser to use for lookup before using aResolver.private intprivate final intprivate final Nameprivate booleanprivate intprivate booleanprivate static final Name[]private booleanprivate booleanprivate Resolverprivate intstatic final intThe lookup was successful.private booleanprivate booleanstatic final intThe lookup failed due to a network error.private final intstatic final intThe host exists, but has no records associated with the queried type.static final intThe lookup failed due to a data or server error. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a Lookup object that will find records of type A at the given name in the IN class.Create a Lookup object that will find records of the given name and type in the IN class.Create a Lookup object that will find records of the given name, type, and class.Create a Lookup object that will find records of type A at the given name in the IN class.Create a Lookup object that will find records of the given name and type in the IN class.Create a Lookup object that will find records of the given name, type, and class. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidconvertSearchPathDomainList(List<Name> domains) private voidName[]Returns all known aliases for this name.Record[]Returns the answers from the lookup.static CachegetDefaultCache(int dclass) Gets the Cache that will be used as the default for the specified class by future Lookups.static HostsFileParserGets the defaultHostsFileParserto use for new Lookup instances.static ResolverGets the Resolver that will be used as the default by future Lookups.Gets the search path that will be used as the default by future Lookups.Returns an error string describing the result code of this lookup.intReturns the result code of the lookup.private voidprivate booleanlookupFromHostsFile(Name current) private voidprocessResponse(Name name, SetResponse response) static voidprivate voidreset()private voidRecord[]run()Performs the lookup, using the specified Cache, Resolver, and search path.voidSets the cache to use when performing this lookup.voidsetCredibility(int credibility) Sets the minimum credibility level that will be accepted when performing the lookup.voidsetCycleResults(boolean cycleResults) Controls the behavior if results being returned from the cache should be cycled in a round-robin style (true) or if the raw lookup results should be returned (false).static voidsetDefaultCache(Cache cache, int dclass) Sets the Cache to be used as the default for the specified class by future Lookups.static voidsetDefaultHostsFileParser(HostsFileParser hostsFileParser) Sets the defaultHostsFileParserto use for new Lookup instances.static voidsetDefaultNdots(int ndots) Sets the default ndots to use when performing a lookup, overriding the default value.static voidsetDefaultResolver(Resolver resolver) Sets the default Resolver to be used as the default by future Lookups.static voidsetDefaultSearchPath(String... domains) Sets the search path that will be used as the default by future Lookups.static voidsetDefaultSearchPath(List<Name> domains) Sets the search path to be used as the default by future Lookups.static voidsetDefaultSearchPath(Name... domains) Sets the search path to be used as the default by future Lookups.voidsetNdots(int ndots) Sets ndots to use when performing this lookup, overriding the default value.static voidsetPacketLogger(PacketLogger logger) Sets a custom logger that will be used to log the sent and received packets.voidsetResolver(Resolver resolver) Sets the resolver to use when performing this lookup.voidsetSearchPath(String... domains) Sets the search path to use when performing this lookup.voidsetSearchPath(List<Name> domains) Sets the search path to use when performing this lookup.voidsetSearchPath(Name... domains) Sets the search path to use when performing this lookup.
-
Field Details
-
defaultResolver
-
defaultSearchPath
-
defaultCaches
-
defaultNdots
private static int defaultNdots -
defaultHostsFileParser
-
resolver
-
searchPath
-
ndots
private int ndots -
cache
-
temporaryCache
private boolean temporaryCache -
credibility
private int credibility -
name
-
type
private final int type -
dclass
private final int dclass -
iterations
private int iterations -
foundAlias
private boolean foundAlias -
done
private boolean done -
doneCurrent
private boolean doneCurrent -
aliases
-
answers
-
result
private int result -
error
-
nxdomain
private boolean nxdomain -
badresponse
private boolean badresponse -
badresponseError
-
networkerror
private boolean networkerror -
timedout
private boolean timedout -
nametoolong
private boolean nametoolong -
referral
private boolean referral -
cycleResults
private boolean cycleResults -
maxIterations
private final int maxIterations -
hostsFileParser
Gets or sets the local hosts database parser to use for lookup before using aResolver.- Since:
- 3.4
-
noAliases
-
SUCCESSFUL
public static final int SUCCESSFULThe lookup was successful.- See Also:
-
UNRECOVERABLE
public static final int UNRECOVERABLEThe lookup failed due to a data or server error. Repeating the lookup would not be helpful.- See Also:
-
TRY_AGAIN
public static final int TRY_AGAINThe lookup failed due to a network error. Repeating the lookup may be helpful.- See Also:
-
HOST_NOT_FOUND
public static final int HOST_NOT_FOUNDThe host does not exist.- See Also:
-
TYPE_NOT_FOUND
public static final int TYPE_NOT_FOUNDThe host exists, but has no records associated with the queried type.- See Also:
-
-
Constructor Details
-
Lookup
Create a Lookup object that will find records of the given name, type, and class. The lookup will use the default cache, resolver, and search path, and look for records that are reasonably credible.- Parameters:
name- The name of the desired recordstype- The type of the desired recordsdclass- The class of the desired records- Throws:
IllegalArgumentException- The type is a meta type other than ANY.- See Also:
-
Lookup
Create a Lookup object that will find records of the given name and type in the IN class.- Parameters:
name- The name of the desired recordstype- The type of the desired records- Throws:
IllegalArgumentException- The type is a meta type other than ANY.- See Also:
-
Lookup
Create a Lookup object that will find records of type A at the given name in the IN class.- Parameters:
name- The name of the desired records- See Also:
-
Lookup
Create a Lookup object that will find records of the given name, type, and class.- Parameters:
name- The name of the desired recordstype- The type of the desired recordsdclass- The class of the desired records- Throws:
TextParseException- The name is not a valid DNS nameIllegalArgumentException- The type is a meta type other than ANY.- See Also:
-
Lookup
Create a Lookup object that will find records of the given name and type in the IN class.- Parameters:
name- The name of the desired recordstype- The type of the desired records- Throws:
TextParseException- The name is not a valid DNS nameIllegalArgumentException- The type is a meta type other than ANY.- See Also:
-
Lookup
Create a Lookup object that will find records of type A at the given name in the IN class.- Parameters:
name- The name of the desired records- Throws:
TextParseException- The name is not a valid DNS name- See Also:
-
-
Method Details
-
refreshDefault
public static void refreshDefault() -
getDefaultResolver
Gets the Resolver that will be used as the default by future Lookups.- Returns:
- The default resolver.
-
setDefaultResolver
Sets the default Resolver to be used as the default by future Lookups.- Parameters:
resolver- The default resolver.
-
getDefaultCache
Gets the Cache that will be used as the default for the specified class by future Lookups.- Parameters:
dclass- The class whose cache is being retrieved.- Returns:
- The default cache for the specified class.
-
setDefaultCache
Sets the Cache to be used as the default for the specified class by future Lookups.- Parameters:
cache- The default cache for the specified class.dclass- The class whose cache is being set.
-
getDefaultSearchPath
Gets the search path that will be used as the default by future Lookups.- Returns:
- The default search path.
-
setDefaultSearchPath
Sets the search path to be used as the default by future Lookups.- Parameters:
domains- The default search path.- Throws:
IllegalArgumentException- if a domain in the search path is not absolute and cannot be made absolute.
-
setDefaultSearchPath
Sets the search path to be used as the default by future Lookups.- Parameters:
domains- The default search path.- Throws:
IllegalArgumentException- if a domain in the search path is not absolute and cannot be made absolute.
-
setDefaultSearchPath
Sets the search path that will be used as the default by future Lookups.- Parameters:
domains- The default search path.- Throws:
TextParseException- A name in the array is not a valid DNS name.
-
getDefaultHostsFileParser
Gets the defaultHostsFileParserto use for new Lookup instances.- Since:
- 3.4
-
setDefaultHostsFileParser
Sets the defaultHostsFileParserto use for new Lookup instances.- Since:
- 3.4
-
convertSearchPathDomainList
-
setPacketLogger
Sets a custom logger that will be used to log the sent and received packets. This is only applicable to the default I/O implementations.- Parameters:
logger- The logger
-
reset
private void reset() -
setResolver
Sets the resolver to use when performing this lookup. This overrides the default value.- Parameters:
resolver- The resolver to use.
-
setSearchPath
Sets the search path to use when performing this lookup. This overrides the default value.- Parameters:
domains- An array of names containing the search path.- Throws:
IllegalArgumentException- if a domain in the search path is not absolute and cannot be made absolute.
-
setSearchPath
Sets the search path to use when performing this lookup. This overrides the default value.- Parameters:
domains- An array of names containing the search path.- Throws:
IllegalArgumentException- if a domain in the search path is not absolute and cannot be made absolute.
-
setSearchPath
Sets the search path to use when performing this lookup. This overrides the default value.- Parameters:
domains- An array of names containing the search path.- Throws:
TextParseException- A name in the array is not a valid DNS name.
-
setCache
Sets the cache to use when performing this lookup. This overrides the default value. If the results of this lookup should not be permanently cached, null can be provided here.- Parameters:
cache- The cache to use.- Throws:
IllegalArgumentException- If the DClass of the cache doesn't match this Lookup's DClass.
-
setDefaultNdots
public static void setDefaultNdots(int ndots) Sets the default ndots to use when performing a lookup, overriding the default value. Specifically, this refers to the number of "dots" which, if present in a name, indicate that a lookup for the absolute name should be attempted before appending any search path elements.- Parameters:
ndots- The ndots value to use, which must be greater than or equal to 0.
-
setNdots
public void setNdots(int ndots) Sets ndots to use when performing this lookup, overriding the default value. Specifically, this refers to the number of "dots" which, if present in a name, indicate that a lookup for the absolute name should be attempted before appending any search path elements.- Parameters:
ndots- The ndots value to use, which must be greater than or equal to 0.
-
setCredibility
public void setCredibility(int credibility) Sets the minimum credibility level that will be accepted when performing the lookup. This defaults to Credibility.NORMAL.- Parameters:
credibility- The minimum credibility level.
-
setCycleResults
public void setCycleResults(boolean cycleResults) Controls the behavior if results being returned from the cache should be cycled in a round-robin style (true) or if the raw lookup results should be returned (false).- Parameters:
cycleResults- The desired behavior of the order of the results
-
follow
-
processResponse
-
lookup
-
lookupFromHostsFile
-
resolve
-
run
Performs the lookup, using the specified Cache, Resolver, and search path.- Returns:
- The answers, or null if none are found.
-
checkDone
private void checkDone() -
getAnswers
Returns the answers from the lookup.- Returns:
- The answers, or null if none are found.
- Throws:
IllegalStateException- The lookup has not completed.
-
getAliases
Returns all known aliases for this name. Whenever a CNAME/DNAME is followed, an alias is added to this array. The last element in this array will be the owner name for records in the answer, if there are any.- Returns:
- The aliases.
- Throws:
IllegalStateException- The lookup has not completed.
-
getResult
public int getResult()Returns the result code of the lookup.- Returns:
- The result code, which can be SUCCESSFUL, UNRECOVERABLE, TRY_AGAIN, HOST_NOT_FOUND, or TYPE_NOT_FOUND.
- Throws:
IllegalStateException- The lookup has not completed.
-
getErrorString
Returns an error string describing the result code of this lookup.- Returns:
- A string, which may either directly correspond the result code or be more specific.
- Throws:
IllegalStateException- The lookup has not completed.
-