Java Code Examples for org.xbill.DNS.Record#getType()
The following examples show how to use
org.xbill.DNS.Record#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenAliasHelper.java From xmrwallet with Apache License 2.0 | 5 votes |
@Override protected Boolean doInBackground(String... args) { //main(); if (args.length != 1) return false; String name = args[0]; if ((name == null) || (name.isEmpty())) return false; //pointless trying to lookup nothing Timber.d("Resolving %s", name); try { SimpleResolver sr = new SimpleResolver(DNSSEC_SERVERS[new Random().nextInt(DNSSEC_SERVERS.length)]); ValidatingResolver vr = new ValidatingResolver(sr); vr.setTimeout(0, DNS_LOOKUP_TIMEOUT); vr.loadTrustAnchors(new ByteArrayInputStream(ROOT.getBytes("ASCII"))); Record qr = Record.newRecord(Name.fromConstantString(name + "."), Type.TXT, DClass.IN); Message response = vr.send(Message.newQuery(qr)); final int rcode = response.getRcode(); if (rcode != Rcode.NOERROR) { Timber.i("Rcode: %s", Rcode.string(rcode)); for (RRset set : response.getSectionRRsets(Section.ADDITIONAL)) { if (set.getName().equals(Name.root) && set.getType() == Type.TXT && set.getDClass() == ValidatingResolver.VALIDATION_REASON_QCLASS) { Timber.i("Reason: %s", ((TXTRecord) set.first()).getStrings().get(0)); } } return false; } else { dnssec = response.getHeader().getFlag(Flags.AD); for (Record record : response.getSectionArray(Section.ANSWER)) { if (record.getType() == Type.TXT) { txts.addAll(((TXTRecord) record).getStrings()); } } } } catch (IOException | IllegalArgumentException ex) { return false; } return true; }
Example 2
Source File: ForwardLookupHelper.java From yeti with MIT License | 5 votes |
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; }
Example 3
Source File: jnamed.java From dnsjava with BSD 2-Clause "Simplified" License | 4 votes |
byte[] generateReply(Message query, byte[] in, Socket s) { Header header; boolean badversion; int maxLength; int flags = 0; header = query.getHeader(); if (header.getFlag(Flags.QR)) { return null; } if (header.getRcode() != Rcode.NOERROR) { return errorMessage(query, Rcode.FORMERR); } if (header.getOpcode() != Opcode.QUERY) { return errorMessage(query, Rcode.NOTIMP); } Record queryRecord = query.getQuestion(); TSIGRecord queryTSIG = query.getTSIG(); TSIG tsig = null; if (queryTSIG != null) { tsig = TSIGs.get(queryTSIG.getName()); if (tsig == null || tsig.verify(query, in, null) != Rcode.NOERROR) { return formerrMessage(in); } } OPTRecord queryOPT = query.getOPT(); if (s != null) { maxLength = 65535; } else if (queryOPT != null) { maxLength = Math.max(queryOPT.getPayloadSize(), 512); } else { maxLength = 512; } if (queryOPT != null && (queryOPT.getFlags() & ExtendedFlags.DO) != 0) { flags = FLAG_DNSSECOK; } Message response = new Message(query.getHeader().getID()); response.getHeader().setFlag(Flags.QR); if (query.getHeader().getFlag(Flags.RD)) { response.getHeader().setFlag(Flags.RD); } response.addRecord(queryRecord, Section.QUESTION); Name name = queryRecord.getName(); int type = queryRecord.getType(); int dclass = queryRecord.getDClass(); if (type == Type.AXFR && s != null) { return doAXFR(name, query, tsig, queryTSIG, s); } if (!Type.isRR(type) && type != Type.ANY) { return errorMessage(query, Rcode.NOTIMP); } byte rcode = addAnswer(response, name, type, dclass, 0, flags); if (rcode != Rcode.NOERROR && rcode != Rcode.NXDOMAIN) { return errorMessage(query, rcode); } addAdditional(response, flags); if (queryOPT != null) { int optflags = (flags == FLAG_DNSSECOK) ? ExtendedFlags.DO : 0; OPTRecord opt = new OPTRecord((short) 4096, rcode, (byte) 0, optflags); response.addRecord(opt, Section.ADDITIONAL); } response.setTSIG(tsig, Rcode.NOERROR, queryTSIG); return response.toWire(maxLength); }