本文整理汇总了Java中org.xbill.DNS.Record.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Record.getType方法的具体用法?Java Record.getType怎么用?Java Record.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xbill.DNS.Record
的用法示例。
在下文中一共展示了Record.getType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMultiSRV
import org.xbill.DNS.Record; //导入方法依赖的package包/类
public List<DNSServiceRecord> getMultiSRV(String key) throws ConfigException {
String qkey = fullyQualify(key);
List<DNSServiceRecord> result = new ArrayList<DNSServiceRecord>();
List<Record> list = m_records.get(makeHostKey(qkey));
if (list == null) {
throw new NotFoundException("No such record: " + makeHostKey(qkey));
}
for (Record r : list) {
if (r.getType() != Type.SRV) {
continue;
}
result.add(new DNSServiceRecord(((SRVRecord) r).rdataToString()));
}
return result;
}
示例2: resolve
import org.xbill.DNS.Record; //导入方法依赖的package包/类
private List<InetAddress> resolve(String key) throws UnknownHostException {
List<InetAddress> result = new ArrayList<InetAddress>();
List<Record> list = m_records.get(key);
if (list != null)
for (Record r : list)
if (r.getType() == Type.A)
result.add(InetAddress.getByName(r.rdataToString()));
else if ((r.getType() == Type.CNAME)) {
List<Record> cnamelist = m_records.get(r.rdataToString());
for (Record r1 : cnamelist) {
result.add(InetAddress.getByName(r1.rdataToString()));
}
}
return result;
}
示例3: findAddresses
import org.xbill.DNS.Record; //导入方法依赖的package包/类
private String[] findAddresses(Name target, Record[] records) {
ArrayList<String> addresses = new ArrayList<String>();
for (Record record : records) {
if (target == null || target.equals(record.getName())) {
int recordType = record.getType();
if (Type.A == recordType)
addresses.add(((ARecord)record).getAddress().getHostAddress());
else if (Type.AAAA == recordType)
addresses.add(((AAAARecord)record).getAddress().getHostAddress());
}
}
if (addresses.size() == 0)
return null;
return addresses.toArray(new String[addresses.size()]);
}
示例4: atLeastOneSupportedAlgorithm
import org.xbill.DNS.Record; //导入方法依赖的package包/类
/**
* Determines if at least one of the DS records in the RRset has a supported
* algorithm.
*
* @param dsRRset The RR set to search in.
* @return True when at least one DS record uses a supported algorithm,
* false otherwise.
*/
static boolean atLeastOneSupportedAlgorithm(RRset dsRRset) {
Iterator<?> it = dsRRset.rrs();
while (it.hasNext()) {
Record r = (Record)it.next();
if (r.getType() == Type.DS) {
if (isAlgorithmSupported(((DSRecord)r).getAlgorithm())) {
return true;
}
// do nothing, there could be another DS we understand
}
}
return false;
}
示例5: atLeastOneDigestSupported
import org.xbill.DNS.Record; //导入方法依赖的package包/类
/**
* Determines if at least one of the DS records in the RRset has a supported
* digest algorithm.
*
* @param dsRRset The RR set to search in.
* @return True when at least one DS record uses a supported digest
* algorithm, false otherwise.
*/
static boolean atLeastOneDigestSupported(RRset dsRRset) {
Iterator<?> it = dsRRset.rrs();
while (it.hasNext()) {
Record r = (Record)it.next();
if (r.getType() == Type.DS) {
if (isDigestSupported(((DSRecord)r).getDigestID())) {
return true;
}
// do nothing, there could be another DS we understand
}
}
return false;
}
示例6: attemptZoneTransfer
import org.xbill.DNS.Record; //导入方法依赖的package包/类
public static List<ForwardLookupResult> attemptZoneTransfer(String domain, List<ForwardLookupResult> nameServers) throws TextParseException {
List<ForwardLookupResult> result = new ArrayList<>();
ZoneTransferIn xfr;
Iterator i = nameServers.iterator();
for (ForwardLookupResult nameServer : nameServers) {
try {
xfr = ZoneTransferIn.newAXFR(new Name(domain), nameServer.getIpAddress(), null);
List records = xfr.run();
for (Iterator it = records.iterator(); it.hasNext();) {
Record r = (Record) it.next();
if (r.getType() == 1) {
ForwardLookupResult rec = new ForwardLookupResult(domain);
String hostName = ((ARecord) r).getName().toString().toLowerCase();
if (hostName.endsWith(".")) {
hostName = hostName.substring(0, hostName.length() - 1);
}
rec.setHostName(hostName);
rec.setIpAddress(((ARecord) r).getAddress().getHostAddress());
rec.setLookupType("A");
result.add(rec);
}
}
} catch (IOException ioex) {
Logger.getLogger("ForwardLookupHelper.attemptZoneTransfer").log(Level.WARNING, null, ioex);
} catch (ZoneTransferException zex) {
Log.debug("ForwardLookupHelper.attemptZoneTransfer: Failed zonetransfer");
}
}
return result;
}
示例7: firstA
import org.xbill.DNS.Record; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected String firstA(Message response) {
RRset[] sectionRRsets = response.getSectionRRsets(Section.ANSWER);
if (sectionRRsets.length > 0) {
Iterator<Record> rrs = sectionRRsets[0].rrs();
while (rrs.hasNext()) {
Record r = rrs.next();
if (r.getType() == Type.A) {
return ((ARecord)r).getAddress().getHostAddress();
}
}
}
return null;
}
示例8: process
import org.xbill.DNS.Record; //导入方法依赖的package包/类
/**
* Processes a DNS query.
*
* @param sock
* Socket to listen to
*/
private void process(DatagramSocket sock) {
try {
byte[] in = new byte[UDP_SIZE];
// Read the question
DatagramPacket indp = new DatagramPacket(in, UDP_SIZE);
indp.setLength(UDP_SIZE);
sock.receive(indp);
Message msg = new Message(in);
Header header = msg.getHeader();
Record question = msg.getQuestion();
// Prepare a response
Message response = new Message(header.getID());
response.getHeader().setFlag(Flags.QR);
response.addRecord(question, Section.QUESTION);
Name name = question.getName();
boolean hasRecords = false;
String txt = txtRecords.get(name.toString(true));
if (question.getType() == Type.TXT && txt != null) {
response.addRecord(new TXTRecord(name, DClass.IN, TTL, txt), Section.ANSWER);
hasRecords = true;
LOG.info("dns-01: {} {} IN TXT \"{}\"", name, TTL, txt);
}
InetAddress a = aRecords.get(name.toString(true));
if (question.getType() == Type.A && a != null) {
response.addRecord(new ARecord(name, DClass.IN, TTL, a), Section.ANSWER);
hasRecords = true;
LOG.info("dns-01: {} {} IN A {}", name, TTL, a.getHostAddress());
}
if (!hasRecords) {
response.getHeader().setRcode(Rcode.NXDOMAIN);
LOG.warn("dns-01: Cannot answer: {}", question);
}
// Send the response
byte[] resp = response.toWire();
DatagramPacket outdp = new DatagramPacket(resp, resp.length, indp.getAddress(), indp.getPort());
sock.send(outdp);
} catch (Exception ex) {
LOG.error("Failed to process query", ex);
}
}
示例9: lookup
import org.xbill.DNS.Record; //导入方法依赖的package包/类
private Message lookup(Set<Name> stack, String[] addresses, Message query) throws IOException {
Message msg = getCached(query);
if (msg != null)
return msg;
if (addresses == null)
return null;
Resolver resolver = createResolver(addresses);
try {
msg = resolver.send(query);
} catch (IOException e) {
return null;
}
if (msg == null)
return null;
// Found the authoritative answer
if (msg.getHeader().getFlag(Flags.AA))
return msg;
Record[] authority = msg.getSectionArray(Section.AUTHORITY);
for (Record record : authority) {
if (Type.NS == record.getType()) {
Name nameserver = ((NSRecord)record).getTarget();
// Try to find glue for the record first
Record[] additional = msg.getSectionArray(Section.ADDITIONAL);
addresses = findAddresses(nameserver, additional);
if (stack.contains(nameserver)) // Loop - cannot go there
continue;
stack.add(nameserver);
if (stack.size() > MAX_RECURSION_STACK) // Prevent recursion spinning out of control
return null;
// No glue found - lookup target recursively
if (addresses == null)
addresses = findAddressesRecursive(stack, nameserver);
// Chase down to the next level
Message resp = lookup(stack, addresses, query);
if (resp != null) {
addCached(resp);
return resp;
}
}
}
return null; // Just couldn't do it
}
示例10: loadTrustAnchors
import org.xbill.DNS.Record; //导入方法依赖的package包/类
/**
* Load the trust anchor file into the trust anchor store. The trust anchors
* are currently stored in a zone file format list of DNSKEY or DS records.
*
* @param data The trust anchor data.
* @throws IOException when the trust anchor data could not be read.
*/
@SuppressWarnings("unchecked")
public void loadTrustAnchors(InputStream data) throws IOException {
// First read in the whole trust anchor file.
Master master = new Master(data, Name.root, 0);
List<Record> records = new ArrayList<Record>();
Record mr;
while ((mr = master.nextRecord()) != null) {
records.add(mr);
}
// Record.compareTo() should sort them into DNSSEC canonical order.
// Don't care about canonical order per se, but do want them to be
// formable into RRsets.
Collections.sort(records);
SRRset currentRrset = new SRRset();
for (Record r : records) {
// Skip RR types that cannot be used as trust anchors.
if (r.getType() != Type.DNSKEY && r.getType() != Type.DS) {
continue;
}
// If our current set is empty, we can just add it.
if (currentRrset.size() == 0) {
currentRrset.addRR(r);
continue;
}
// If this record matches our current RRset, we can just add it.
if (currentRrset.getName().equals(r.getName()) && currentRrset.getType() == r.getType() && currentRrset.getDClass() == r.getDClass()) {
currentRrset.addRR(r);
continue;
}
// Otherwise, we add the rrset to our set of trust anchors and begin
// a new set
this.trustAnchors.store(currentRrset);
currentRrset = new SRRset();
currentRrset.addRR(r);
}
// add the last rrset (if it was not empty)
if (currentRrset.size() > 0) {
this.trustAnchors.store(currentRrset);
}
}
示例11: parseRecord
import org.xbill.DNS.Record; //导入方法依赖的package包/类
private Record parseRecord(String line) throws IOException {
try {
Master ma = new Master(new ByteArrayInputStream(line.getBytes()), null, 3600);
Record r = ma.nextRecord();
if (r.getType() == Type.RRSIG) {
RRSIGRecord rr = (RRSIGRecord)r;
// unbound directly uses the DER format for DSA signatures
// instead of the format specified in rfc2536#section-3
if (rr.getAlgorithm() == Algorithm.DSA && rr.getSignature().length > 41) {
Method DSASignaturetoDNS = DNSSEC.class.getDeclaredMethod("DSASignaturetoDNS", byte[].class, int.class);
DSASignaturetoDNS.setAccessible(true);
byte[] signature = (byte[])DSASignaturetoDNS.invoke(null, rr.getSignature(), 0);
RRSIGRecord fixed = new RRSIGRecord(rr.getName(), rr.getDClass(), rr.getTTL(), rr.getTypeCovered(), rr.getAlgorithm(), rr.getOrigTTL(),
rr.getExpire(), rr.getTimeSigned(), rr.getFootprint(), rr.getSigner(), signature);
Field f = getField(RRSIGRecord.class, "labels");
f.setAccessible(true);
f.set(fixed, rr.getLabels());
r = fixed;
}
}
return r;
}
catch (Exception ex) {
if (ex.getMessage() != null && ex.getMessage().contains("expected an integer")) {
String[] data = line.split("\\s");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.length; i++) {
if (this.algoStrings.contains(data[i])) {
sb.append(Algorithm.value(data[i]));
}
else {
sb.append(data[i]);
}
sb.append(' ');
}
return parseRecord(sb.toString());
}
else {
throw new IOException(line, ex);
}
}
}