本文整理汇总了Java中org.xbill.DNS.ResolverConfig类的典型用法代码示例。如果您正苦于以下问题:Java ResolverConfig类的具体用法?Java ResolverConfig怎么用?Java ResolverConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResolverConfig类属于org.xbill.DNS包,在下文中一共展示了ResolverConfig类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hostToAddr
import org.xbill.DNS.ResolverConfig; //导入依赖的package包/类
public String hostToAddr(String hostname) {
if (hostname == null || hostname=="") {
hostname = ResolverConfig.getCurrentConfig().server();
if (hostname==null){
hostname="0";
}
}
InetAddress addr;
try {
if (hostname.equals("0"))
addr = InetAddress.getLocalHost();
else
addr = InetAddress.getByName(hostname);
InetSocketAddress address = new InetSocketAddress(addr, 53);
return address.getAddress().getHostAddress();
} catch (UnknownHostException e){
}
return "";
}
示例2: getSystemDNSServers
import org.xbill.DNS.ResolverConfig; //导入依赖的package包/类
/**
* Get System DNS Servers
* @return A list of InetAddress objects contains the system's configured DNS servers
*/
public List<InetAddress> getSystemDNSServers() {
List<InetAddress> dnsServers = new ArrayList<InetAddress>();
ResolverConfig resolverConfig = new ResolverConfig();
try {
for(String dnsHostIp : resolverConfig.servers()) {
if(dnsHostIp.equals("")) continue;
dnsServers.add(InetAddress.getByName(dnsHostIp));
}
} catch (Exception e) {
e.printStackTrace();
}
return dnsServers;
}
示例3: singleDnsServer
import org.xbill.DNS.ResolverConfig; //导入依赖的package包/类
@Test
public void singleDnsServer() {
String[] dnsServers = { "8.8.8.8" };
try {
ResolverConfig mockResolver = PowerMockito.mock(ResolverConfig.class);
when(mockResolver.servers()).thenReturn(dnsServers);
PowerMockito.whenNew(ResolverConfig.class).withNoArguments().thenReturn(mockResolver);
} catch (Exception e) {
fail("Test Setup Failed: " + e.toString());
}
DNSBootstrapService testService = new DNSBootstrapService();
List<InetAddress> addrs = testService.getSystemDNSServers();
assertEquals("Validate Addr Count", 1, addrs.size());
assertEquals("Validate Address", "8.8.8.8", addrs.get(0).getHostAddress());
}
示例4: multipleDnsServers
import org.xbill.DNS.ResolverConfig; //导入依赖的package包/类
@Test
public void multipleDnsServers() {
String[] dnsServers = { "8.8.8.8", "8.8.4.4" };
try {
ResolverConfig mockResolver = PowerMockito.mock(ResolverConfig.class);
when(mockResolver.servers()).thenReturn(dnsServers);
PowerMockito.whenNew(ResolverConfig.class).withNoArguments().thenReturn(mockResolver);
} catch (Exception e) {
fail("Test Setup Failed: " + e.toString());
}
DNSBootstrapService testService = new DNSBootstrapService();
List<InetAddress> addrs = testService.getSystemDNSServers();
assertEquals("Validate Addr Count", 2, addrs.size());
assertEquals("Validate Address", "8.8.8.8", addrs.get(0).getHostAddress());
assertEquals("Validate Address", "8.8.4.4", addrs.get(1).getHostAddress());
}
示例5: noDnsServers
import org.xbill.DNS.ResolverConfig; //导入依赖的package包/类
@Test
public void noDnsServers() {
String[] dnsServers = { };
try {
ResolverConfig mockResolver = PowerMockito.mock(ResolverConfig.class);
when(mockResolver.servers()).thenReturn(dnsServers);
PowerMockito.whenNew(ResolverConfig.class).withNoArguments().thenReturn(mockResolver);
} catch (Exception e) {
fail("Test Setup Failed: " + e.toString());
}
DNSBootstrapService testService = new DNSBootstrapService();
List<InetAddress> addrs = testService.getSystemDNSServers();
assertEquals("Validate Addr Count", 0, addrs.size());
}
示例6: getResolvers
import org.xbill.DNS.ResolverConfig; //导入依赖的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;
}
示例7: discoverResources
import org.xbill.DNS.ResolverConfig; //导入依赖的package包/类
@Override
public Set<DiscoveredResourceDetails> discoverResources(
ResourceDiscoveryContext context)
throws InvalidPluginConfigurationException, Exception {
ResolverConfig conf = new ResolverConfig();
Set<DiscoveredResourceDetails> set = new HashSet<DiscoveredResourceDetails>();
for (String server: conf.servers()) {
String name = "DNS server " + server;
DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
context.getResourceType(),
server, // database key
name, // UI name
null, // Version
name,
context.getDefaultPluginConfiguration(),
null); // process info
set.add(detail);
}
return set;
}
示例8: onReceive
import org.xbill.DNS.ResolverConfig; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
ResolverConfig.refresh();
}
示例9: onReceive
import org.xbill.DNS.ResolverConfig; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
ResolverConfig.refresh();
}