Search in sources :

Example 16 with SimpleResolver

use of org.xbill.DNS.SimpleResolver in project opennms by OpenNMS.

the class DnsProvisioningAdapter method afterPropertiesSet.

/**
 * <p>afterPropertiesSet</p>
 *
 * @throws java.lang.Exception if any.
 */
@Override
public void afterPropertiesSet() throws Exception {
    Assert.notNull(m_nodeDao, "DnsProvisioner requires a NodeDao which is not null.");
    // load current nodes into the map
    m_template.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus arg0) {
            createDnsRecordMap();
        }
    });
    String levelString = System.getProperty("importer.adapter.dns.level");
    if (levelString != null) {
        Integer level = Integer.getInteger(levelString);
        if (level != null && level.intValue() > 0)
            m_level = level;
    }
    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, DnsProvisioningAdapter will not do anything!");
    }
}
Also used : TransactionStatus(org.springframework.transaction.TransactionStatus) SimpleResolver(org.xbill.DNS.SimpleResolver) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 17 with SimpleResolver

use of org.xbill.DNS.SimpleResolver in project Signal-Android by WhisperSystems.

the class CustomDns method lookup.

@Override
@NonNull
public List<InetAddress> lookup(@NonNull String hostname) throws UnknownHostException {
    Resolver resolver = new SimpleResolver(dnsHostname);
    Lookup lookup = doLookup(hostname);
    lookup.setResolver(resolver);
    Record[] records = lookup.run();
    if (records != null) {
        List<InetAddress> ipv4Addresses = Stream.of(records).filter(r -> r.getType() == Type.A).map(r -> (ARecord) r).map(ARecord::getAddress).toList();
        if (ipv4Addresses.size() > 0) {
            return ipv4Addresses;
        }
    }
    throw new UnknownHostException(hostname);
}
Also used : Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) UnknownHostException(java.net.UnknownHostException) Dns(okhttp3.Dns) InetAddress(java.net.InetAddress) Log(org.signal.core.util.logging.Log) Type(org.xbill.DNS.Type) List(java.util.List) ARecord(org.xbill.DNS.ARecord) SimpleResolver(org.xbill.DNS.SimpleResolver) Record(org.xbill.DNS.Record) Resolver(org.xbill.DNS.Resolver) Lookup(org.xbill.DNS.Lookup) SimpleResolver(org.xbill.DNS.SimpleResolver) Resolver(org.xbill.DNS.Resolver) UnknownHostException(java.net.UnknownHostException) Lookup(org.xbill.DNS.Lookup) ARecord(org.xbill.DNS.ARecord) Record(org.xbill.DNS.Record) SimpleResolver(org.xbill.DNS.SimpleResolver) InetAddress(java.net.InetAddress) NonNull(androidx.annotation.NonNull)

Example 18 with SimpleResolver

use of org.xbill.DNS.SimpleResolver in project ecf by eclipse.

the class DnsSdAdvertiserServiceTest method createSRVRecord.

private void createSRVRecord() throws TextParseException, IOException, UnknownHostException {
    // create a service manually
    final Name zone = Name.fromString(DnsSdTestHelper.REG_DOMAIN + ".");
    final Name type = Name.fromString("_" + DnsSdTestHelper.REG_SCHEME + "._" + DnsSdTestHelper.PROTO, zone);
    final String s = serviceInfo.getPriority() + " " + serviceInfo.getWeight() + " " + serviceInfo.getLocation().getPort() + " " + serviceInfo.getLocation().getHost() + ".";
    final Record record = Record.fromString(type, Type.SRV, DClass.IN, DnsSdTestHelper.TTL, s, zone);
    final Update update = new Update(zone);
    update.add(record);
    final SimpleResolver resolver = new SimpleResolver(DnsSdTestHelper.DNS_SERVER);
    resolver.setTCP(true);
    resolver.setTSIGKey(new TSIG(DnsSdTestHelper.TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY));
    final Message response = resolver.send(update);
    final int rcode = response.getRcode();
    assertTrue("", rcode == 0);
}
Also used : Message(org.xbill.DNS.Message) SRVRecord(org.xbill.DNS.SRVRecord) Record(org.xbill.DNS.Record) TXTRecord(org.xbill.DNS.TXTRecord) TSIG(org.xbill.DNS.TSIG) Update(org.xbill.DNS.Update) SimpleResolver(org.xbill.DNS.SimpleResolver) Name(org.xbill.DNS.Name)

Example 19 with SimpleResolver

use of org.xbill.DNS.SimpleResolver in project ecf by eclipse.

the class DnsSdDiscoveryAdvertiser method connect.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.provider.dnssd.DnsSdDiscoveryLocator#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
	 */
public void connect(final ID aTargetID, final IConnectContext connectContext) throws ContainerConnectException {
    // $NON-NLS-1$ //$NON-NLS-2$
    Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "connect(ID aTargetID, IConnectContext connectContext)", "connecting container");
    // connect can only be called once
    if (targetID != null || getConfig() == null) {
        throw new ContainerConnectException(Messages.DnsSdDiscoveryAdvertiser_Container_Already_Connected);
    }
    // TODO convert non DnsSdServiceTypeIDs into DSTIDs
    if (aTargetID == null) {
        targetID = new DnsSdServiceTypeID();
    } 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();
            resolver.setTCP(true);
        } catch (UnknownHostException e) {
            throw new ContainerConnectException(e);
        }
    }
    // done setting up this provider, send event
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, connectContext));
    fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) UnknownHostException(java.net.UnknownHostException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent) SimpleResolver(org.xbill.DNS.SimpleResolver) Namespace(org.eclipse.ecf.core.identity.Namespace)

Aggregations

SimpleResolver (org.xbill.DNS.SimpleResolver)19 Record (org.xbill.DNS.Record)11 Name (org.xbill.DNS.Name)9 Message (org.xbill.DNS.Message)7 UnknownHostException (java.net.UnknownHostException)6 Lookup (org.xbill.DNS.Lookup)6 Test (org.junit.Test)4 SRVRecord (org.xbill.DNS.SRVRecord)4 Update (org.xbill.DNS.Update)4 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)3 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)3 Resolver (org.xbill.DNS.Resolver)3 TSIG (org.xbill.DNS.TSIG)3 TXTRecord (org.xbill.DNS.TXTRecord)3 InetAddress (java.net.InetAddress)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Endpoint (org.apache.camel.Endpoint)2 ContainerConnectedEvent (org.eclipse.ecf.core.events.ContainerConnectedEvent)2 ContainerConnectingEvent (org.eclipse.ecf.core.events.ContainerConnectingEvent)2