use of org.xbill.DNS.SimpleResolver in project opennms by OpenNMS.
the class DnsMonitorIT method testDnsJavaQuadARecord.
@Test
public void testDnsJavaQuadARecord() throws IOException {
assumeTrue(!Boolean.getBoolean("skipIpv6Tests"));
final Lookup l = new Lookup("ipv6.example.com", Type.AAAA);
// make sure we use a temporary cache so don't get results from a previously cached query
// from another test
l.setCache(null);
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);
}
use of org.xbill.DNS.SimpleResolver in project opennms by OpenNMS.
the class DnsMonitorIT method testNoAnswer.
@Test
@JUnitDNSServer(port = 9153, zones = {})
public void testNoAnswer() throws Exception {
final Lookup l = new Lookup("example.com", Type.AAAA);
// make sure we use a temporary cache so don't get results from a previously cached query
// from another test
l.setCache(null);
final SimpleResolver resolver = new SimpleResolver("::1");
resolver.setPort(9153);
l.setResolver(resolver);
l.run();
// and NXRRSET record should be sent meaning that the server has no records for
// example.com at all. This results in a null answers. This is result 4 I think
System.out.println("result: " + l.getResult());
final Record[] answers = l.getAnswers();
assertNull(answers);
}
use of org.xbill.DNS.SimpleResolver in project opennms by OpenNMS.
the class ReverseDnsProvisioningAdapter method afterPropertiesSet.
/**
* <p>afterPropertiesSet</p>
*
* @throws java.lang.Exception if any.
*/
@Override
public void afterPropertiesSet() throws Exception {
String dnsServer = System.getProperty("importer.adapter.dns.server");
if (!StringUtils.isBlank(dnsServer)) {
LOG.info("DNS property found: {}", dnsServer);
if (dnsServer.contains(":")) {
final String[] serverAddress = dnsServer.split(":");
m_resolver = new SimpleResolver(serverAddress[0]);
m_resolver.setPort(Integer.valueOf(serverAddress[1]));
} else {
m_resolver = new SimpleResolver(dnsServer);
}
// Doesn't work for some reason, haven't figured out why yet
String key = System.getProperty("importer.adapter.dns.privatekey");
if (key != null && key.length() > 0) {
m_signature = key;
m_resolver.setTSIGKey(TSIG.fromString(m_signature));
}
} else {
LOG.warn("no DNS server configured, ReverseDnsProvisioningAdapter will not do anything!");
}
}
use of org.xbill.DNS.SimpleResolver in project ecf by eclipse.
the class DnsSdDiscoveryAdvertiser method sendToServer.
protected void sendToServer(final IServiceInfo serviceInfo, final boolean mode) {
Assert.isNotNull(serviceInfo);
Assert.isLegal(serviceInfo.getServiceID() instanceof DnsSdServiceID);
final DnsSdServiceID serviceID = (DnsSdServiceID) serviceInfo.getServiceID();
try {
// TYPE.SRV
final Record srvRecord = serviceID.toSRVRecord();
// TYPE.TXT
final Record[] txtRecords = serviceID.toTXTRecords(srvRecord);
final Name name = serviceID.getDnsName();
final String[] registrationDomains = getRegistrationDomains(serviceID.getServiceTypeID());
for (int i = 0; i < registrationDomains.length; i++) {
final Name zone = new Name(registrationDomains[i]);
// $NON-NLS-1$
final Name fqdn = new Name(name.toString() + "." + zone.toString());
final Update update = new Update(zone);
// TYPE.SRV
if (mode == ADD) {
// TODO add absent/present condition checks
update.replace(srvRecord.withName(fqdn));
} else {
update.delete(srvRecord.withName(fqdn));
}
// TYPE.TXT
for (int j = 0; j < txtRecords.length; j++) {
if (mode == ADD) {
update.add(txtRecords[j].withName(fqdn));
} else {
update.delete(txtRecords[j].withName(fqdn));
}
}
// set up a the resolver for the given domain (a scope might use different domains)
final Collection dnsServers = getUpdateDomain(zone);
if (dnsServers.size() == 0) {
throw new DnsSdDiscoveryException(Messages.DnsSdDiscoveryAdvertiser_No_DynDns_Servers_Found);
}
for (final Iterator iterator = dnsServers.iterator(); iterator.hasNext(); ) {
final SRVRecord dnsServer = (SRVRecord) iterator.next();
// try to send msg and fail gracefully if more dns servers are available
final Name target = dnsServer.getTarget();
final Message response;
final InetAddress byName;
try {
byName = InetAddress.getByName(target.toString());
((SimpleResolver) resolver).setAddress(byName);
((SimpleResolver) resolver).setPort(dnsServer.getPort());
response = resolver.send(update);
} catch (UnknownHostException uhe) {
if (iterator.hasNext()) {
continue;
} else {
throw new DnsSdDiscoveryException(uhe);
}
} catch (EOFException eof) {
if (iterator.hasNext()) {
continue;
} else {
throw new DnsSdDiscoveryException(eof);
}
}
// catch some errors and fall back to the next dnsServer
if (response.getRcode() != Rcode.NOERROR) {
if (iterator.hasNext()) {
continue;
} else {
throw DnsSdDiscoveryException.getException(response.getRcode());
}
}
}
}
} catch (Exception e) {
throw new DnsSdDiscoveryException(e);
}
}
use of org.xbill.DNS.SimpleResolver in project ecf by eclipse.
the class DnsSdDiscoveryLocator method connect.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ecf.core.IContainer#connect(org.eclipse.ecf.core.identity.ID,
* org.eclipse.ecf.core.security.IConnectContext)
*/
public void connect(ID aTargetID, IConnectContext connectContext) throws ContainerConnectException {
// connect can only be called once
if (targetID != null || getConfig() == null) {
throw new ContainerConnectException(Messages.DnsSdDiscoveryLocator_Container_Already_Connected);
}
// fall back to the search path as last resort
if (aTargetID == null || !(aTargetID instanceof DnsSdServiceTypeID)) {
ResolverConfig config = new ResolverConfig();
Name[] searchPaths = config.searchPath();
if (searchPaths != null && searchPaths.length > 0) {
targetID = new DnsSdServiceTypeID();
targetID.setSearchPath(searchPaths);
} else {
throw new ContainerConnectException(Messages.DnsSdDiscoveryLocator_No_Target_ID);
}
} else {
final Namespace ns = getConnectNamespace();
try {
targetID = (DnsSdServiceTypeID) ns.createInstance(new Object[] { aTargetID });
} catch (IDCreateException e) {
throw new ContainerConnectException(e);
}
}
// instantiate a default resolver
if (resolver == null) {
try {
resolver = new SimpleResolver();
} catch (UnknownHostException e) {
throw new ContainerConnectException(e);
}
}
// read browsing domains for the given targetID/searchpath and merge with existing
targetID.addSearchPath(getBrowsingDomains(targetID));
// done setting up this provider, send event
fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, connectContext));
fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
}
Aggregations