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);
}
}
}
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);
}
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);
}
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");
}
}
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);
}
}
Aggregations