/** * Retrieve a list of currently configured DNS servers. * @return The server array. */ public String[] findDNS() { String[] result = findDNSByReflection(); if (result != null) { LOGGER.fine("Got DNS servers via reflection: " + Arrays.toString(result)); return result; } result = findDNSByExec(); if (result != null) { LOGGER.fine("Got DNS servers via exec: " + Arrays.toString(result)); return result; } // fallback for ipv4 and ipv6 connectivity // see https://developers.google.com/speed/public-dns/docs/using LOGGER.fine("No DNS found? Using fallback [8.8.8.8, [2001:4860:4860::8888]]"); return new String[]{"8.8.8.8", "[2001:4860:4860::8888]"}; }
/** * Query a specific server for one entry. * @param q The question section of the DNS query. * @param host The dns server host. * @return The response (or null on timeout/error). * @throws IOException On IOErrors. */ public DNSMessage query(Question q, String host) throws IOException { return query(q, host, 53); }
/** * Query the system nameservers for a single entry of the class IN * (which is used for MX, SRV, A, AAAA and most other RRs). * * @param name The DNS name to request. * @param type The DNS type to request (SRV, A, AAAA, ...). * @return The response (or null on timeout/error). */ public DNSMessage query(String name, TYPE type) { Question q = new Question(name, type, CLASS.IN); return query(q); }
/** * Query a nameserver for a single entry. * @param name The DNS name to request. * @param type The DNS type to request (SRV, A, AAAA, ...). * @param clazz The class of the request (usually IN for Internet). * @param host The DNS server host. * @return The response (or null on timeout / failure). * @throws IOException On IO Errors. */ public DNSMessage query(String name, TYPE type, CLASS clazz, String host) throws IOException { Question q = new Question(name, type, clazz); return query(q, host); }
/** * Query a nameserver for a single entry. * @param name The DNS name to request. * @param type The DNS type to request (SRV, A, AAAA, ...). * @param clazz The class of the request (usually IN for Internet). * @param host The DNS server host. * @param port The DNS server port. * @return The response (or null on timeout / failure). * @throws IOException On IO Errors. */ public DNSMessage query(String name, TYPE type, CLASS clazz, String host, int port) throws IOException { Question q = new Question(name, type, clazz); return query(q, host, port); }
/** * Query the system nameservers for a single entry of any class. * * This can be used to determine the name server version, if name * is version.bind, type is TYPE.TXT and clazz is CLASS.CH. * * @param name The DNS name to request. * @param type The DNS type to request (SRV, A, AAAA, ...). * @param clazz The class of the request (usually IN for Internet). * @return The response (or null on timeout/error). */ public DNSMessage query(String name, TYPE type, CLASS clazz) { Question q = new Question(name, type, clazz); return query(q); }