Java Code Examples for org.xbill.DNS.Lookup#run()
The following examples show how to use
org.xbill.DNS.Lookup#run() .
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: GoogleResolverCheck.java From entrada with GNU General Public License v3.0 | 7 votes |
@Override protected List<String> fetch() { try { Resolver resolver = new SimpleResolver(); // dns resolvers may take a long time to return a response. resolver.setTimeout(timeout); Lookup l = new Lookup(StringUtils.endsWith(hostname, ".") ? hostname : hostname + ".", Type.TXT); // always make sure the cache is empty l.setCache(new Cache()); l.setResolver(resolver); Record[] records = l.run(); if (records != null && records.length > 0) { return parse(records[0]); } } catch (Exception e) { log.error("Problem while adding Google resolvers, continue without", e); } log.error("No Google resolver addresses found"); return Collections.emptyList(); }
Example 2
Source File: XBillDnsSrvResolver.java From dns-java with Apache License 2.0 | 7 votes |
@Override public List<LookupResult> resolve(final String fqdn) { Lookup lookup = lookupFactory.forName(fqdn); Record[] queryResult = lookup.run(); switch (lookup.getResult()) { case Lookup.SUCCESSFUL: return toLookupResults(queryResult); case Lookup.HOST_NOT_FOUND: // fallthrough case Lookup.TYPE_NOT_FOUND: LOG.warn("No results returned for query '{}'; result from XBill: {} - {}", fqdn, lookup.getResult(), lookup.getErrorString()); return ImmutableList.of(); default: throw new DnsException( String.format("Lookup of '%s' failed with code: %d - %s ", fqdn, lookup.getResult(), lookup.getErrorString())); } }
Example 3
Source File: lookup.java From dnsjava with BSD 2-Clause "Simplified" License | 6 votes |
public static void main(String[] args) throws Exception { int type = Type.A; int start = 0; if (args.length > 2 && args[0].equals("-t")) { type = Type.value(args[1]); if (type < 0) { throw new IllegalArgumentException("invalid type"); } start = 2; } for (int i = start; i < args.length; i++) { Lookup l = new Lookup(args[i], type); l.run(); printAnswer(args[i], l); } }
Example 4
Source File: Helperfunctions.java From open-rmbt with Apache License 2.0 | 6 votes |
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; }
Example 5
Source File: DNSResolver.java From burp-javascript-security-extension with GNU General Public License v3.0 | 5 votes |
/** * Follow the CNAME breadcrumb trail and find any which can't resolve * @param hostName a string of the hostname, or fqdn, to lookup * @return a set of strings which list the CNAME entries which could not be resolved */ public Set<String> getBadCnames(String hostName){ Set<String> retval = new TreeSet<String>(); try { Lookup thisLookup = new Lookup(hostName, CNAME); thisLookup.setResolver(myResolver); Record[] results = thisLookup.run(); if (results != null){ List<Record> records = Arrays.asList(results); for (Record record : records){ CNAMERecord thisRecord = (CNAMERecord) record; String target = thisRecord.getTarget().toString(); if (hasRecordsOfType(target, CNAME)){ // check for more cnames down the tree retval.addAll(getBadCnames(target)); } else { if (!(hasRecordsOfType(target, A) || hasRecordsOfType(target, AAAA))){ // This one doesn't point to anything retval.add(target); } } } } } catch (TextParseException e){ System.err.println("[SRI][-] There was an error parsing the name " + hostName); } return retval; }
Example 6
Source File: Utils.java From ShadowsocksRR with Apache License 2.0 | 5 votes |
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 || result.length == 0) { return null; } List<Record> records = new ArrayList<>(Arrays.asList(result)); Collections.shuffle(records); for (Record r : records) { switch (addrType) { case Type.A: return ((ARecord) r).getAddress().getHostAddress(); case Type.AAAA: return ((AAAARecord) r).getAddress().getHostAddress(); default: break; } } } catch (Exception e) { VayLog.e(TAG, "resolve", e); app.track(e); } return null; }
Example 7
Source File: Utils.java From Maying with Apache License 2.0 | 5 votes |
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 || result.length == 0) { return null; } List<Record> records = new ArrayList<>(Arrays.asList(result)); Collections.shuffle(records); for (Record r : records) { switch (addrType) { case Type.A: return ((ARecord) r).getAddress().getHostAddress(); case Type.AAAA: return ((AAAARecord) r).getAddress().getHostAddress(); default: break; } } } catch (Exception e) { VayLog.e(TAG, "resolve", e); ShadowsocksApplication.app.track(e); } return null; }
Example 8
Source File: DNSJavaService.java From james-project with Apache License 2.0 | 5 votes |
/** * Looks up DNS records of the specified type for the specified name. * <p/> * This method is a public wrapper for the private implementation method * * @param namestr the name of the host to be looked up * @param type the type of record desired * @param typeDesc the description of the record type, for debugging purpose */ protected Record[] lookup(String namestr, int type, String typeDesc) throws TemporaryResolutionException { // Name name = null; try { // name = Name.fromString(namestr, Name.root); Lookup l = new Lookup(namestr, type); l.setCache(cache); l.setResolver(resolver); l.setCredibility(dnsCredibility); l.setSearchPath(searchPaths); Record[] r = l.run(); try { if (l.getResult() == Lookup.TRY_AGAIN) { throw new TemporaryResolutionException("DNSService is temporary not reachable"); } else { return r; } } catch (IllegalStateException ise) { // This is okay, because it mimics the original behaviour // TODO find out if it's a bug in DNSJava LOGGER.warn("Error determining result ", ise); throw new TemporaryResolutionException("DNSService is temporary not reachable"); } // return rawDNSLookup(name, false, type, typeDesc); } catch (TextParseException tpe) { // TODO: Figure out how to handle this correctly. LOGGER.error("Couldn't parse name {}", namestr, tpe); return null; } }
Example 9
Source File: AddressLookup.java From mireka with Apache License 2.0 | 5 votes |
private Record[] queryAddressRecords(Name name) throws SendException { Lookup lookup = new Lookup(name); Record[] records = lookup.run(); switch (lookup.getResult()) { case Lookup.SUCCESSFUL: return records; case Lookup.TYPE_NOT_FOUND: throw new SendException("Host " + name + " has no address record (" + lookup.getErrorString() + ")", EnhancedStatus.PERMANENT_UNABLE_TO_ROUTE); case Lookup.HOST_NOT_FOUND: throw new SendException("Host " + name + " is not found (" + lookup.getErrorString() + ")", EnhancedStatus.PERMANENT_UNABLE_TO_ROUTE); case Lookup.TRY_AGAIN: throw new SendException( "DNS network failure while looking up address of " + name + ": " + lookup.getErrorString(), EnhancedStatus.TRANSIENT_DIRECTORY_SERVER_FAILURE); case Lookup.UNRECOVERABLE: throw new SendException( "Unrecoverable DNS error while looking up address of " + name + ": " + lookup.getErrorString(), EnhancedStatus.PERMANENT_UNABLE_TO_ROUTE); default: throw new SendException( "Unknown DNS status while looking up address of " + name + ": " + lookup.getResult() + ". " + lookup.getErrorString(), EnhancedStatus.PERMANENT_INTERNAL_ERROR); } }
Example 10
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 11
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 12
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 13
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 14
Source File: DNSResolver.java From spring-boot with Apache License 2.0 | 3 votes |
public static void main(String[] args) { // System.err.println("Outcome: " // + CheckEmailObj.checkEmail("[email protected]")); String qqhostName = "qq.com"; String qqhostName2 = "outlook.com"; System.out.println(DNSResolver.checkDNS(qqhostName2, false)); // System.out.println(DNSResolver.checkDNS("outlook.com", true)); try { Lookup lookup = new Lookup(qqhostName2, Type.A); lookup.run(); for(Record r : lookup.getAnswers()) System.out.println(r); } catch (TextParseException e) { e.printStackTrace(); } // System.out.println( MailChecker.validate("[email protected]")); }