org.xbill.DNS.TXTRecord Java Examples
The following examples show how to use
org.xbill.DNS.TXTRecord.
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: DNS.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
/** * Query a text record for the given domain from DNS * * @param domain the domain to lookup the DNS for a text record * @return the text record content, if found, null otherwise */ @SuppressWarnings ("unchecked") public String queryText (String domain) { String rc = null; Record[] r = query (domain, Type.TXT); if (r != null) { rc = ""; for (int n = 0; n < r.length; ++n) { List <String> answ = ((TXTRecord) r[n]).getStrings (); for (int m = 0; m < answ.size (); ++m) { String s = answ.get (m); if ((s != null) && (s.length () > 0)) { rc += s; } } } } return rc; }
Example #2
Source File: GoogleResolverCheck.java From entrada with GNU General Public License v3.0 | 6 votes |
private List<String> parse(Record record) { TXTRecord txt = (TXTRecord) record; List<String> subnets = new ArrayList<>(); @SuppressWarnings("unchecked") List<String> lines = txt.getStrings(); for (String line : lines) { String[] parts = StringUtils.split(line, " "); if (parts.length == 2) { if (log.isDebugEnabled()) { log.debug("Add Google resolver IP range: " + parts[0]); } subnets.add(parts[0]); } } if (subnets.isEmpty()) { log.error("No Google resolver addresses found"); } return subnets; }
Example #3
Source File: DNSJavaService.java From james-project with Apache License 2.0 | 6 votes |
@Override public Collection<String> findTXTRecords(String hostname) { TimeMetric timeMetric = metricFactory.timer("findTXTRecords"); List<String> txtR = new ArrayList<>(); Record[] records = lookupNoException(hostname, Type.TXT, "TXT"); try { if (records != null) { for (Record record : records) { TXTRecord txt = (TXTRecord) record; txtR.add(txt.rdataToString()); } } return txtR; } finally { timeMetric.stopAndPublish(); } }
Example #4
Source File: Dnsbl.java From mireka with Apache License 2.0 | 6 votes |
private String concatenateTxtRecordValues(Record[] records) { if (records == null || records.length == 0) return null; StringBuilder builder = new StringBuilder(); for (Record record : records) { TXTRecord txtRecord = (TXTRecord) record; if (builder.length() != 0) builder.append(EOL); for (Object string : txtRecord.getStrings()) { if (builder.length() != 0) builder.append(EOL); builder.append(string); } } return builder.toString(); }
Example #5
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 #6
Source File: Helperfunctions.java From open-rmbt with Apache License 2.0 | 5 votes |
public static Long getASN(final InetAddress adr) { try { final Name postfix; if (adr instanceof Inet6Address) postfix = Name.fromConstantString("origin6.asn.cymru.com"); else postfix = Name.fromConstantString("origin.asn.cymru.com"); final Name name = getReverseIPName(adr, postfix); System.out.println("lookup: " + name); final Lookup lookup = new Lookup(name, Type.TXT); 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 TXTRecord) { final TXTRecord txt = (TXTRecord) record; @SuppressWarnings("unchecked") final List<String> strings = txt.getStrings(); if (strings != null && !strings.isEmpty()) { final String result = strings.get(0); final String[] parts = result.split(" ?\\| ?"); if (parts != null && parts.length >= 1) return new Long(parts[0]); } } } catch (final Exception e) { } return null; }
Example #7
Source File: Helperfunctions.java From open-rmbt with Apache License 2.0 | 5 votes |
public static String getASName(final long asn) { try { final Name postfix = Name.fromConstantString("asn.cymru.com."); final Name name = new Name(String.format("AS%d", asn), postfix); System.out.println("lookup: " + name); final Lookup lookup = new Lookup(name, Type.TXT); 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 TXTRecord) { final TXTRecord txt = (TXTRecord) record; @SuppressWarnings("unchecked") final List<String> strings = txt.getStrings(); if (strings != null && !strings.isEmpty()) { System.out.println(strings); final String result = strings.get(0); final String[] parts = result.split(" ?\\| ?"); if (parts != null && parts.length >= 1) return parts[4]; } } } catch (final Exception e) { } return null; }
Example #8
Source File: Helperfunctions.java From open-rmbt with Apache License 2.0 | 5 votes |
public static String getAScountry(final long asn) { try { final Name postfix = Name.fromConstantString("asn.cymru.com."); final Name name = new Name(String.format("AS%d", asn), postfix); System.out.println("lookup: " + name); final Lookup lookup = new Lookup(name, Type.TXT); 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 TXTRecord) { final TXTRecord txt = (TXTRecord) record; @SuppressWarnings("unchecked") final List<String> strings = txt.getStrings(); if (strings != null && !strings.isEmpty()) { final String result = strings.get(0); final String[] parts = result.split(" ?\\| ?"); if (parts != null && parts.length >= 1) return parts[1]; } } } catch (final Exception e) { } return null; }
Example #9
Source File: DNSUtils.java From buddycloud-android with Apache License 2.0 | 5 votes |
/** * Adapted from https://code.google.com/p/asmack/source/browse/src/custom/org/jivesoftware/smack/util/DNSUtil.java * * @param domain * @return * @throws TextParseException */ @SuppressWarnings("unchecked") private static String resolveAPITXT(String domain) throws TextParseException { Lookup lookup = new Lookup(TXT_PREFIX + domain, Type.TXT); Record recs[] = lookup.run(); if (recs == null) { throw new RuntimeException("Could not lookup domain."); } Map<String, String> stringMap = null; for (Record rec : recs) { String rData = rec.rdataToString().replaceAll("\"", ""); List<String> rDataTokens = Arrays.asList(rData.split("\\s+")); TXTRecord record = new TXTRecord(rec.getName(), rec.getDClass(), rec.getTTL(), rDataTokens); List<String> strings = record.getStrings(); if (strings != null && strings.size() > 0) { stringMap = parseStrings(strings); break; } } if (stringMap == null) { throw new RuntimeException("Domain has no TXT records for buddycloud."); } String host = stringMap.get("host"); String protocol = stringMap.get("protocol"); String path = stringMap.get("path"); String port = stringMap.get("port"); path = path == null || path.equals("/") ? "" : path; port = port == null ? "" : port; return protocol + "://" + host + ":" + port + path; }
Example #10
Source File: DNS.java From yeti with MIT License | 4 votes |
public static TXTRecord getTXTRecord(String hostName) { return null; }
Example #11
Source File: DataAPI.java From yeti with MIT License | 4 votes |
public TXTRecord getTXTRecord(String hostName) { return null; }