本文整理汇总了Java中org.xbill.DNS.Record类的典型用法代码示例。如果您正苦于以下问题:Java Record类的具体用法?Java Record怎么用?Java Record使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Record类属于org.xbill.DNS包,在下文中一共展示了Record类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import org.xbill.DNS.Record; //导入依赖的package包/类
/**
* Attempts to resolve an SMTP server address, given the destination e-mail address.
*
* @param email The e-mail address used for the lookup.
* @return An optional, potentially containing
*/
protected Optional<String> resolve(String email) {
Optional<String> domainOptional = extractDomain(email);
if (!domainOptional.isPresent()) {
return Optional.empty();
}
String mailDomain = domainOptional.get();
try {
Lookup dnsLookup = new Lookup(mailDomain, Type.MX);
List<Record> records = Arrays.asList(dnsLookup.run());
if (records.isEmpty()) {
return Optional.empty();
}
return chooseBestRecord(records);
} catch (TextParseException e) {
e.printStackTrace();
}
return Optional.empty();
}
示例2: getUpdatedListOfServers
import org.xbill.DNS.Record; //导入依赖的package包/类
@Override
public List<ServiceCallServer> getUpdatedListOfServers(String name) {
final Lookup lookup = lookupFactory.apply(name);
final Record[] records = lookup.run();
List<ServiceCallServer> servers;
if (Objects.nonNull(records) && lookup.getResult() == Lookup.SUCCESSFUL) {
servers = Arrays.stream(records)
.filter(SRVRecord.class::isInstance)
.map(SRVRecord.class::cast)
.sorted(DnsServiceCallServer.COMPARATOR)
.map(DnsServiceCallServer::new)
.collect(Collectors.toList());
} else {
servers = Collections.emptyList();
}
return servers;
}
示例3: resolve
import org.xbill.DNS.Record; //导入依赖的package包/类
public static String resolve(String host, int addrType) {
try {
Lookup lookup = new Lookup(host, addrType);
SimpleResolver resolver = new SimpleResolver("114.114.114.114");
resolver.setTimeout(5);
lookup.setResolver(resolver);
Record[] result = lookup.run();
if (result == null) return null;
List<Record> records = java.util.Arrays.asList(result);
java.util.Collections.shuffle(records);
for (Record record : records) {
if (addrType == Type.A) {
return ((ARecord) record).getAddress().getHostAddress();
} else if (addrType == Type.AAAA) {
return ((AAAARecord) record).getAddress().getHostAddress();
}
}
} catch (Exception ex) {
return null;
}
return null;
}
示例4: reverseLookupByAddress
import org.xbill.DNS.Record; //导入依赖的package包/类
/**
* reverse lookup an IP address using a specified DNS host and port
*
* @param resolverHost name server hostname or IP address
* @param resolverPort name server port
* @param address the IP address to reverse lookup
* @return a comma separated list of names or an empty string when unable to resolve
*/
public String reverseLookupByAddress(String resolverHost, int resolverPort, InetAddress address) {
try {
SimpleResolver resolver = new SimpleResolver(resolverHost);
resolver.setPort(resolverPort);
Lookup lookup = new Lookup(fromAddress(address), PTR);
Record[] records = lookup.run();
if (records != null) {
List<String> addresses =
of(records)
.filter(it -> it instanceof PTRRecord)
.map(it -> ((PTRRecord) it).getTarget().toString())
.collect(toList());
return collectionToCommaDelimitedString(addresses);
} else {
return "";
}
} catch (UnknownHostException e) {
log.warn("unable to resolve using SRV record " + address, e);
return "";
}
}
示例5: testDnsJavaWithDnsServer
import org.xbill.DNS.Record; //导入依赖的package包/类
@Test
public void testDnsJavaWithDnsServer() throws TextParseException, UnknownHostException {
final Lookup l = new Lookup("example.com", Type.AAAA);
final SimpleResolver resolver = new SimpleResolver("::1");
resolver.setPort(9153);
l.setResolver(resolver);
l.run();
System.out.println("result: " + l.getResult());
final Record[] answers = l.getAnswers();
assertEquals(answers.length, 1);
final Record record = answers[0];
System.err.println(record.getTTL());
if(l.getResult() == Lookup.SUCCESSFUL) {
System.out.println(l.getAnswers()[0].rdataToString());
}
assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}
示例6: done
import org.xbill.DNS.Record; //导入依赖的package包/类
static void doAXFR(Message response) throws IOException {
System.out.println("; java dig 0.0 <> " + name + " axfr");
if (response.isSigned()) {
System.out.print(";; TSIG ");
if (response.isVerified())
System.out.println("ok");
else
System.out.println("failed");
}
if (response.getRcode() != Rcode.NOERROR) {
System.out.println(response);
return;
}
Record [] records = response.getSectionArray(Section.ANSWER);
for (int i = 0; i < records.length; i++)
System.out.println(records[i]);
System.out.print(";; done (");
System.out.print(response.getHeader().getCount(Section.ANSWER));
System.out.print(" records, ");
System.out.print(response.getHeader().getCount(Section.ADDITIONAL));
System.out.println(" additional)");
}
示例7: reverseDNSLookup
import org.xbill.DNS.Record; //导入依赖的package包/类
public static String reverseDNSLookup(final InetAddress adr)
{
try
{
final Name name = ReverseMap.fromAddress(adr);
final Lookup lookup = new Lookup(name, Type.PTR);
lookup.setResolver(new SimpleResolver());
lookup.setCache(null);
final Record[] records = lookup.run();
if (lookup.getResult() == Lookup.SUCCESSFUL)
for (final Record record : records)
if (record instanceof PTRRecord)
{
final PTRRecord ptr = (PTRRecord) record;
return ptr.getTarget().toString();
}
}
catch (final Exception e)
{
}
return null;
}
示例8: dnsLookup
import org.xbill.DNS.Record; //导入依赖的package包/类
/**
* Dns lookup more efficient than the INetAddress.getHostName(ip)
*
* @param hostIp
* @return
* @throws IOException
*/
public String dnsLookup(final String hostIp) {
try {
final Name name = ReverseMap.fromAddress(hostIp);
final int type = Type.PTR;
final int dclass = DClass.IN;
final Record rec = Record.newRecord(name, type, dclass);
final Message query = Message.newQuery(rec);
final Message response = _resolver.send(query);
final Record[] answers = response.getSectionArray(Section.ANSWER);
if (answers.length > 0) {
String ret = answers[0].rdataToString();
if (ret.endsWith(".")) {
ret = ret.substring(0, ret.length() - 1);
}
return ret;
}
} catch (final IOException e) {
LOGGER.warn("Failed to resolve hostname for " + hostIp, e);
}
return UNKNOWN_HOST;
}
示例9: chooseBestRecord
import org.xbill.DNS.Record; //导入依赖的package包/类
/**
* Chooses the best SMTP server, given a list of MX records.
* TODO: Actually choose the best record!
*
* @param records The MX records.
* @return An optional, possibly containing an SMTP server address.
*/
private Optional<String> chooseBestRecord(List<Record> records) {
TreeMultimap<Integer, String> recordMap = decodeRecords(records);
if(!recordMap.isEmpty()) {
List<String> topRecords = new LinkedList<>(recordMap.asMap().firstEntry().getValue());
if(!topRecords.isEmpty()) {
String record = topRecords.get(0);
return Optional.of(record.substring(0, record.length() - 1));
}
}
return Optional.empty();
}
示例10: decodeRecords
import org.xbill.DNS.Record; //导入依赖的package包/类
/**
* Decodes a list of MX records into a tree map, ranking them automatically.
*
* @param records The list of MX records.
* @return The tree map containing ranked MX records.
*/
private TreeMultimap<Integer, String> decodeRecords(List<Record> records) {
TreeMultimap<Integer, String> recordMap = TreeMultimap.create(Ordering.natural(), Ordering.natural());
records.forEach(record -> {
String[] split = record.rdataToString().split(" ");
if (split.length >= 2) {
try {
int rank = Integer.parseInt(split[0]);
String domain = split[1];
recordMap.put(rank, domain);
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
}
});
return recordMap;
}
示例11: getPortFromResponse
import org.xbill.DNS.Record; //导入依赖的package包/类
public static int getPortFromResponse(Message m) {
for (int i = 0; i < 4; i++) {
try { // Can do something with the counts field here, instead of
// cycling through all of these
Record[] records = m.getSectionArray(i);
if (records != null) {
for (int j = 0; j < records.length; j++) {
if ((records[j]).getClass().equals(TXTRecord.class)) {
return Integer.valueOf(
((String) (((TXTRecord) (records[j]))
.getStrings().get(0)))).intValue();
}
}
}
} catch (IndexOutOfBoundsException e) {
// carry on!
}
}
return -999;
}
示例12: lookupSRVRecords
import org.xbill.DNS.Record; //导入依赖的package包/类
@Override
public List<SRVRecord> lookupSRVRecords(String name) throws TextParseException {
List<SRVRecord> res = new ArrayList<SRVRecord>();
Lookup lookup = new Lookup(name, Type.SRV);
Record[] recs = lookup.run();
if (recs == null)
return res;
for (Record record : recs) {
org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record;
if (srvRecord != null && srvRecord.getTarget() != null) {
String host = srvRecord.getTarget().toString();
int port = srvRecord.getPort();
int priority = srvRecord.getPriority();
int weight = srvRecord.getWeight();
SRVRecord r = new SRVRecord(host, port, priority, weight);
res.add(r);
}
}
return res;
}
示例13: toRecord
import org.xbill.DNS.Record; //导入依赖的package包/类
/**
* @param ip, like "192.168.1.1"
* @return the complete DNS record for that IP.
*/
@Converter
public static Record toRecord(String ip) throws IOException {
Resolver res = new ExtendedResolver();
Name name = ReverseMap.fromAddress(ip);
int type = Type.PTR;
int dclass = DClass.IN;
Record rec = Record.newRecord(name, type, dclass);
Message query = Message.newQuery(rec);
Message response = res.send(query);
Record[] answers = response.getSectionArray(Section.ANSWER);
if (answers.length == 0) {
return null;
} else {
return answers[0];
}
}
示例14: testDNSWithNameHeaderAndType
import org.xbill.DNS.Record; //导入依赖的package包/类
@Test
@Ignore("Testing behind nat produces timeouts")
public void testDNSWithNameHeaderAndType() throws Exception {
resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedMessagesMatches(new Predicate() {
public boolean matches(Exchange exchange) {
Record[] record = (Record[]) exchange.getIn().getBody();
return record[0].getName().toString().equals("www.example.com.");
}
});
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("dns.name", "www.example.com");
headers.put("dns.type", "A");
template.sendBodyAndHeaders("hello", headers);
resultEndpoint.assertIsSatisfied();
}
示例15: resolveHostByName
import org.xbill.DNS.Record; //导入依赖的package包/类
/**
* resolves an A record by its name using a specified DNS host and port
*
* @param resolverHost name server hostname or IP address
* @param resolverPort name server port
* @param name the DNS name of the A record - the name to resolve
* @return a comma separated list of IP addresses or an empty string when unable to resolve
*/
public String resolveHostByName(String resolverHost, int resolverPort, String name) {
try {
SimpleResolver resolver = new SimpleResolver(resolverHost);
resolver.setPort(resolverPort);
Lookup lookup = new Lookup(name, A);
Record[] records = lookup.run();
if (records != null) {
List<String> addresses =
of(records)
.filter(it -> it instanceof ARecord)
.map(it -> ((ARecord) it).getAddress().getHostAddress())
.collect(toList());
return collectionToCommaDelimitedString(addresses);
} else {
return "";
}
} catch (UnknownHostException | TextParseException e) {
log.warn("unable to resolve using A record " + name, e);
return "";
}
}