org.xbill.DNS.TextParseException Java Examples
The following examples show how to use
org.xbill.DNS.TextParseException.
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: DataAPI.java From yeti with MIT License | 6 votes |
public List<ARecordResult> getARecord(String hostName) throws TextParseException { List<ARecordResult> entries = null; Record[] recs = new Lookup(hostName, Type.A).run(); if (recs != null) { if (recs.length > 0) { entries = new ArrayList<>(); for (Record record : recs) { ARecordResult foundSubDomain = new ARecordResult(NetworkTools.getDomainFromHost(hostName)); foundSubDomain.setHostName(hostName); String ipAddress = ((ARecord) record).getAddress().getHostAddress(); foundSubDomain.setIpAddress(ipAddress); foundSubDomain.setLookupType("A"); entries.add(foundSubDomain); } } } return entries; }
Example #2
Source File: NetworkTools.java From yeti with MIT License | 6 votes |
public static String getDomainFromHost(String host) { String tmpHost = host; if (host.isEmpty()) { return ""; } while (true) { try { if (!tmpHost.startsWith("www.")) { Record[] recs = new Lookup(tmpHost, Type.SOA).run(); if (recs != null) { return tmpHost; } } if (tmpHost.contains(".")) { tmpHost = tmpHost.split("\\.", 2)[1]; } else { break; } } catch (TextParseException ex) { Logger.getLogger("networkTools.getDomainFromHost").log(Level.SEVERE, null, ex); break; } } return ""; }
Example #3
Source File: DNS.java From yeti with MIT License | 6 votes |
public static List<ARecordResult> getARecord(String hostName) throws TextParseException { List<ARecordResult> entries = null; Record[] recs = new Lookup(hostName, Type.A).run(); if (recs != null) { if (recs.length > 0) { entries = new ArrayList<>(); for (Record record : recs) { ARecordResult foundSubDomain = new ARecordResult(NetworkTools.getDomainFromHost(hostName)); foundSubDomain.setHostName(hostName); String ipAddress = ((ARecord) record).getAddress().getHostAddress(); foundSubDomain.setIpAddress(ipAddress); foundSubDomain.setLookupType("A"); entries.add(foundSubDomain); } } } return entries; }
Example #4
Source File: Output.java From helios with Apache License 2.0 | 6 votes |
public static String shortHostname(final String host) { final Name root = Name.fromConstantString("."); final Name hostname; try { hostname = Name.fromString(host, root); } catch (TextParseException e) { throw new IllegalArgumentException("Invalid hostname '" + host + "'"); } final ResolverConfig currentConfig = ResolverConfig.getCurrentConfig(); if (currentConfig != null) { final Name[] searchPath = currentConfig.searchPath(); if (searchPath != null) { for (final Name domain : searchPath) { if (hostname.subdomain(domain)) { return hostname.relativize(domain).toString(); } } } } return hostname.toString(); }
Example #5
Source File: ForwardLookupHelper.java From yeti with MIT License | 6 votes |
public static List<ForwardLookupResult> getARecord(String hostName, String domainName) throws TextParseException { List<ForwardLookupResult> entries = null; if (hostName != null && !hostName.isEmpty() && domainName != null && !domainName.isEmpty()) { Record[] recs = new Lookup(hostName, Type.A).run(); if (recs != null) { if (recs.length > 0) { entries = new ArrayList<>(); for (Record record : recs) { ForwardLookupResult foundSubDomain = new ForwardLookupResult(domainName); foundSubDomain.setHostName(hostName); String ipAddress = ((ARecord) record).getAddress().getHostAddress(); foundSubDomain.setIpAddress(ipAddress); foundSubDomain.setLookupType("A"); entries.add(foundSubDomain); } } } } return entries; }
Example #6
Source File: YileController.java From yeti with MIT License | 6 votes |
@Override public void addHostFromUrl(String url, String baseUrl) { try { URL aUrl = new URL(url); URL sUrl = new URL(baseUrl); String domain = NetworkTools.getDomainFromHost(aUrl.getHost()); YileResult res = new YileResult(domain); res.setHostName(aUrl.getHost()); res.setSource(sUrl.getHost()); res.setUrl(url); try { String name = domain.split("\\.", 2)[0]; String tld = domain.split("\\.", 2)[1]; res.setRegistrant(NetworkTools.getHostNameWhoisResult(name, tld, true)); res.setIPAddress(NetworkTools.getIpFromHost(aUrl.getHost()).get(0)); } catch (TextParseException tpe) { Logger.getLogger("yileController.yileWorker.addHostFromUrl").log(Level.SEVERE, null, tpe); } addResult(res); } catch (MalformedURLException ex) { Logger.getLogger("yileController.yileWorker.addHostFromUrl").log(Level.SEVERE, null, ex); } }
Example #7
Source File: XBillDnsSrvResolverTest.java From dns-java with Apache License 2.0 | 6 votes |
private Message messageWithNodes(String query, String[] names) throws TextParseException { Name queryName = Name.fromString(query); Record question = Record.newRecord(queryName, Type.SRV, DClass.IN); Message queryMessage = Message.newQuery(question); Message result = new Message(); result.setHeader(queryMessage.getHeader()); result.addRecord(question, Section.QUESTION); for (String name1 : names) { result.addRecord( new SRVRecord(queryName, DClass.IN, 1, 1, 1, 8080, Name.fromString(name1)), Section.ANSWER); } return result; }
Example #8
Source File: ForwardLookupHelper.java From yeti with MIT License | 6 votes |
public static List<ForwardLookupResult> getAAAARecord(String hostName, String domainName) throws TextParseException { List<ForwardLookupResult> entries = null; if (hostName != null && !hostName.isEmpty() && domainName != null && !domainName.isEmpty()) { Record[] recs = new Lookup(hostName, Type.AAAA).run(); if (recs != null) { if (recs.length > 0) { entries = new ArrayList<>(); for (Record record : recs) { ForwardLookupResult foundSubDomain = new ForwardLookupResult(domainName); foundSubDomain.setHostName(hostName); String ipAddress = ((AAAARecord) record).getAddress().getHostAddress(); foundSubDomain.setIpAddress(ipAddress); foundSubDomain.setLookupType("A"); entries.add(foundSubDomain); } } } } return entries; }
Example #9
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 #10
Source File: DNSServiceAddressResolver.java From cloudbreak with Apache License 2.0 | 5 votes |
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException { String result; try { Record[] records = new Lookup(query, Type.SRV).run(); if (records != null && records.length > 0) { SRVRecord srv = (SRVRecord) records[0]; result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort(); } else { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved"); } } catch (TextParseException e) { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e); } return result; }
Example #11
Source File: DNSServiceAddressResolver.java From cloudbreak with Apache License 2.0 | 5 votes |
private String dnsSrvLookup(String query) { String result; try { Record[] records = new Lookup(query, Type.SRV).run(); if (records != null && records.length > 0) { SRVRecord srv = (SRVRecord) records[0]; result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort(); } else { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved"); } } catch (TextParseException e) { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e); } return result; }
Example #12
Source File: DNSServiceAddressResolver.java From cloudbreak with Apache License 2.0 | 5 votes |
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException { String result; try { Record[] records = new Lookup(query, Type.SRV).run(); if (records != null && records.length > 0) { SRVRecord srv = (SRVRecord) records[0]; result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort(); } else { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved"); } } catch (TextParseException e) { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e); } return result; }
Example #13
Source File: DNSServiceAddressResolver.java From cloudbreak with Apache License 2.0 | 5 votes |
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException { String result; try { Record[] records = new Lookup(query, Type.SRV).run(); if (records != null && records.length > 0) { SRVRecord srv = (SRVRecord) records[0]; result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort(); } else { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved"); } } catch (TextParseException e) { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e); } return result; }
Example #14
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 #15
Source File: ForwardLookupHelper.java From yeti with MIT License | 5 votes |
public static boolean isWildCard(String domain) { if (domain != null && !domain.isEmpty()) { try { String subDomain = String.format("%s.%s", ConfigSettings.getWildCardSubdomain(), domain); if (ForwardLookupHelper.getARecord(subDomain, domain) == null) { return false; } } catch (TextParseException ex) { Log.debug(ex.toString()); } } return true; }
Example #16
Source File: TldController.java From yeti with MIT License | 5 votes |
@Override protected String doInBackground() { try { expandDomain(domain); } catch (TextParseException ex) { Logger.getLogger(TldController.class.getName() + ":TldWorker -> doInBackground").log(Level.SEVERE, null, ex); } return "Done"; }
Example #17
Source File: TldController.java From yeti with MIT License | 5 votes |
public void expandDomain(String domainToCheck) throws TextParseException { String domainName = null; // Check for domain name alias - CNAME Record[] recs = new Lookup(domainToCheck, Type.CNAME).run(); if (recs != null && recs.length != 0) { domainName = ((CNAMERecord) recs[0]).getName().canonicalize().toString(true); Log.debug("Found: " + domainName + "CNAME rec: " + domainName); } // Now get the SOA record that would signify a domain exists recs = new Lookup(domainToCheck, Type.SOA).run(); for (int idx = 0; idx < retryCount; idx++) { if (recs != null) { if (domainName == null) { domainName = ((SOARecord) recs[0]).getName().canonicalize().toString(true); Log.debug("Found: " + domainName + " SOA rec: " + domainName); } DomainResult newDomain = new DomainResult(domainName); newDomain.setNameServer(((SOARecord) recs[0]).getHost().toString(true)); newDomain.setAdminName(((SOARecord) recs[0]).getAdmin().toString(true)); String name = domainToCheck.split("\\.", 2)[0]; String tld = domainToCheck.split("\\.", 2)[1]; newDomain.setRegistrant(NetworkTools.getHostNameWhoisResult(name, tld, true)); Map<String, String> attrs = new HashMap<>(); attrs.put(DataStore.DNS_RECORD, DataStore.SOA); newDomain.setAttributes(attrs); addResult(newDomain); break; } } }
Example #18
Source File: DNS.java From yeti with MIT License | 5 votes |
public static SOARecordResult getSOARecord(String domainName) { SOARecordResult newDomain = null; try { Record[] recs = new Lookup(domainName, Type.SOA).run(); if (recs != null) { domainName = ((SOARecord) recs[0]).getName().canonicalize().toString(true); newDomain = new SOARecordResult(domainName); newDomain.setNameServer(((SOARecord) recs[0]).getHost().toString(true)); newDomain.setAdminName(((SOARecord) recs[0]).getAdmin().toString(true)); } } catch (TextParseException tpe) { Logger.getLogger(DNS.class.getName()).log(Level.SEVERE, null, tpe); } return newDomain; }
Example #19
Source File: NetworkTools.java From yeti with MIT License | 5 votes |
public static List<String> getIpFromHost(String hostname) throws TextParseException { List<String> result = new ArrayList<>(); Record[] recs = new Lookup(hostname, Type.A).run(); if (recs != null) { if (recs.length > 0) { for (Record rec : recs) { String ipAddress = ((ARecord) rec).getAddress().toString(); result.add(ipAddress.replace("/", "")); } } } return result; }
Example #20
Source File: Helperfunctions.java From open-rmbt with Apache License 2.0 | 5 votes |
public static Name getReverseIPName(final InetAddress adr, final Name postfix) { final byte[] addr = adr.getAddress(); final StringBuilder sb = new StringBuilder(); if (addr.length == 4) for (int i = addr.length - 1; i >= 0; i--) { sb.append(addr[i] & 0xFF); if (i > 0) sb.append("."); } else { final int[] nibbles = new int[2]; for (int i = addr.length - 1; i >= 0; i--) { nibbles[0] = (addr[i] & 0xFF) >> 4; nibbles[1] = addr[i] & 0xFF & 0xF; for (int j = nibbles.length - 1; j >= 0; j--) { sb.append(Integer.toHexString(nibbles[j])); if (i > 0 || j > 0) sb.append("."); } } } try { return Name.fromString(sb.toString(), postfix); } catch (final TextParseException e) { throw new IllegalStateException("name cannot be invalid"); } }
Example #21
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 #22
Source File: DNSServiceAddressResolver.java From cloudbreak with Apache License 2.0 | 5 votes |
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException { String result; try { Record[] records = new Lookup(query, Type.SRV).run(); if (records != null && records.length > 0) { SRVRecord srv = (SRVRecord) records[0]; result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort(); } else { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved"); } } catch (TextParseException e) { throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e); } return result; }
Example #23
Source File: EdgeDictionaryBean.java From datawave with Apache License 2.0 | 5 votes |
/** * The edge dictionary only has one endpoint. Send redirects for any request to it. */ @GET @Path("/") public Response getEdgeDictionary(@Context UriInfo uriInfo) throws TextParseException, URISyntaxException { URIBuilder builder = remoteEdgeDictionary.buildURI(""); uriInfo.getQueryParameters().forEach((pname, valueList) -> valueList.forEach(pvalue -> builder.addParameter(pname, pvalue))); return Response.temporaryRedirect(builder.build()).build(); }
Example #24
Source File: RemoteHttpService.java From datawave with Apache License 2.0 | 5 votes |
protected URIBuilder buildURI() throws TextParseException { final String host = serviceHost(); final int port = servicePort(); URIBuilder builder = new URIBuilder(); builder.setScheme(serviceScheme()); if (useSrvDns()) { List<LookupResult> results = dnsSrvResolver.resolve(host); if (results != null && !results.isEmpty()) { LookupResult result = results.get(0); builder.setHost(result.host()); builder.setPort(result.port()); // Consul sends the hostname back in its own namespace. Although the A record is included in the // "ADDITIONAL SECTION", Spotify SRV lookup doesn't translate, so we need to do the lookup manually. if (result.host().endsWith(".consul.")) { Record[] newResults = new Lookup(result.host(), Type.A, DClass.IN).run(); if (newResults != null && newResults.length > 0) { builder.setHost(newResults[0].rdataToString()); } else { throw new IllegalArgumentException("Unable to resolve service host " + host + " -> " + result.host() + " -> ???"); } } } else { throw new IllegalArgumentException("Unable to resolve service host: " + host); } } else { builder.setHost(host); builder.setPort(port); } return builder; }
Example #25
Source File: DnsUpdateWriter.java From nomulus with Apache License 2.0 | 5 votes |
private Name toAbsoluteName(String name) { try { return Name.fromString(name, Name.root); } catch (TextParseException e) { throw new RuntimeException( String.format("toAbsoluteName failed for name: %s in zone: %s", name, zoneName), e); } }
Example #26
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 #27
Source File: SimpleLookupFactory.java From dns-java with Apache License 2.0 | 5 votes |
@Override public Lookup forName(String fqdn) { try { final Lookup lookup = new Lookup(fqdn, Type.SRV, DClass.IN); if (resolver != null) { lookup.setResolver(resolver); } return lookup; } catch (TextParseException e) { throw new DnsException("unable to create lookup for name: " + fqdn, e); } }
Example #28
Source File: XBillDnsSrvResolverTest.java From dns-java with Apache License 2.0 | 5 votes |
private Message messageWithRCode(String query, int rcode) throws TextParseException { Name queryName = Name.fromString(query); Record question = Record.newRecord(queryName, Type.SRV, DClass.IN); Message queryMessage = Message.newQuery(question); Message result = new Message(); result.setHeader(queryMessage.getHeader()); result.addRecord(question, Section.QUESTION); result.getHeader().setRcode(rcode); return result; }
Example #29
Source File: SimpleLookupFactoryTest.java From dns-java with Apache License 2.0 | 5 votes |
@Test public void shouldRethrowXBillExceptions() { thrown.expect(DnsException.class); thrown.expectCause(isA(TextParseException.class)); factory.forName("bad\\1 name"); }
Example #30
Source File: BaseResolverConfigProvider.java From dnsjava with BSD 2-Clause "Simplified" License | 5 votes |
protected void addSearchPath(String searchPath) { if (searchPath == null || searchPath.isEmpty()) { return; } try { Name n = Name.fromString(searchPath, Name.root); if (!searchlist.contains(n)) { searchlist.add(n); log.debug("Added {} to search paths", n); } } catch (TextParseException e) { log.warn("Could not parse search path {} as a dns name, ignoring", searchPath); } }