Search in sources :

Example 11 with SimpleResolver

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

the class DnsSdAdvertiserServiceTest method setUp.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.discovery.AbstractDiscoveryTest#setUp()
	 */
protected void setUp() throws Exception {
    super.setUp();
    // purge all SRV records from the test domain
    ZoneTransferIn xfr = ZoneTransferIn.newAXFR(new Name(DnsSdTestHelper.REG_DOMAIN), DnsSdTestHelper.DNS_SERVER, null);
    List records = xfr.run();
    for (Iterator itr = records.iterator(); itr.hasNext(); ) {
        Record record = (Record) itr.next();
        String name = record.getName().toString();
        if (name.startsWith("_" + DnsSdTestHelper.REG_SCHEME + "._" + DnsSdTestHelper.PROTO)) {
            Update update = new Update(Name.fromString(DnsSdTestHelper.REG_DOMAIN + "."));
            update.delete(record);
            SimpleResolver resolver = new SimpleResolver(DnsSdTestHelper.DNS_SERVER);
            resolver.setTCP(true);
            resolver.setTSIGKey(new TSIG(DnsSdTestHelper.TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY));
            Message response = resolver.send(update);
            int rcode = response.getRcode();
            assertTrue("", rcode == 0);
        }
    }
}
Also used : Message(org.xbill.DNS.Message) ZoneTransferIn(org.xbill.DNS.ZoneTransferIn) Iterator(java.util.Iterator) List(java.util.List) 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 12 with SimpleResolver

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

the class DnsSdAdvertiserServiceTest method createTXTRecords.

private void createTXTRecords() throws TextParseException, IOException, UnknownHostException {
    final Name zone = Name.fromString(DnsSdTestHelper.REG_DOMAIN + ".");
    final Name name = Name.fromString("_" + DnsSdTestHelper.REG_SCHEME + "._" + DnsSdTestHelper.PROTO, zone);
    Update update = null;
    final IServiceProperties properties = serviceInfo.getServiceProperties();
    final Enumeration enumeration = properties.getPropertyNames();
    while (enumeration.hasMoreElements()) {
        final Object property = enumeration.nextElement();
        final String key = property.toString();
        final String value = (String) properties.getProperty(key).toString();
        final Record record = Record.fromString(name, Type.TXT, DClass.IN, serviceInfo.getTTL(), key + "=" + value, zone);
        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 : Enumeration(java.util.Enumeration) 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) IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties) SimpleResolver(org.xbill.DNS.SimpleResolver) Name(org.xbill.DNS.Name)

Example 13 with SimpleResolver

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

the class DnsMonitorIT method testDnsJavaResponse.

@Test
public void testDnsJavaResponse() throws IOException {
    final Lookup l = new Lookup("example.com");
    // 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("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);
}
Also used : Lookup(org.xbill.DNS.Lookup) SimpleResolver(org.xbill.DNS.SimpleResolver) Test(org.junit.Test)

Example 14 with SimpleResolver

use of org.xbill.DNS.SimpleResolver in project Unblock163MusicClient-Xposed by bin456789.

the class Utility method getIpByHost.

static String getIpByHost(String domain) throws UnknownHostException, TextParseException {
    if (cnDnsResolver == null)
        cnDnsResolver = new SimpleResolver(Settings.getDnsServer());
    // caches mechanism built-in, just look it up
    Lookup lookup = new Lookup(domain, Type.A);
    lookup.setResolver(cnDnsResolver);
    Record[] records = lookup.run();
    if (lookup.getResult() == Lookup.SUCCESSFUL) {
        // already random, just pick index 0
        return records[0].rdataToString();
    } else {
        throw new RuntimeException("No IP found");
    }
}
Also used : Lookup(org.xbill.DNS.Lookup) Record(org.xbill.DNS.Record) SimpleResolver(org.xbill.DNS.SimpleResolver)

Example 15 with SimpleResolver

use of org.xbill.DNS.SimpleResolver in project camel by apache.

the class DnsWikipediaProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    SimpleResolver resolver = new SimpleResolver();
    int type = Type.TXT;
    Name name = Name.fromString(String.valueOf(exchange.getIn().getHeader(DnsConstants.TERM)) + ".wp.dg.cx", Name.root);
    Record rec = Record.newRecord(name, type, DClass.IN);
    Message query = Message.newQuery(rec);
    Message response = resolver.send(query);
    Record[] records = response.getSectionArray(Section.ANSWER);
    if (records.length > 0) {
        exchange.getIn().setBody(records[0].rdataToString());
    } else {
        exchange.getIn().setBody(null);
    }
}
Also used : Message(org.xbill.DNS.Message) Record(org.xbill.DNS.Record) SimpleResolver(org.xbill.DNS.SimpleResolver) Endpoint(org.apache.camel.Endpoint) Name(org.xbill.DNS.Name)

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