private List<ScoredHost> scoreMatches(final List<String> results) { final ImmutableList.Builder<ScoredHost> scored = ImmutableList.builder(); for (final String name : results) { int score = Integer.MAX_VALUE; for (int i = 0; i < searchPath.length; i++) { if (name.endsWith(searchPath[i].toString())) { if (i < score) { score = i; } } } scored.add(new ScoredHost(name, score)); } return scored.build(); } }
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(); }
@Override protected List<SRVRecord> lookupSRVRecords0(DnsName name, List<HostAddress> failedAddresses, DnssecMode dnssecMode) { List<SRVRecord> res = new ArrayList<>(); Lookup lookup; try { lookup = new Lookup(name.ace, Type.SRV); } catch (TextParseException e) { throw new IllegalStateException(e); } Record[] recs = lookup.run(); if (recs == null) return res; for (Record record : recs) { org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record; if (srvRecord != null && srvRecord.getTarget() != null) { DnsName host = DnsName.from(srvRecord.getTarget().toString()); int port = srvRecord.getPort(); int priority = srvRecord.getPriority(); int weight = srvRecord.getWeight(); List<InetAddress> hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode); if (shouldContinue(name, host, hostAddresses)) { continue; } SRVRecord r = new SRVRecord(host, port, priority, weight, hostAddresses); res.add(r); } } return res; }
/** * Finds PTR records (reverse dns lookups) for the ip address. * * @param ip ip address to lookup. * @return The host name found for the ip address. * @throws UnknownHostException occurs when id is not available in DNS */ public String getHostByAddr(byte[] ip) throws UnknownHostException { try { String addr = DnsUtils.numericToTextFormat(ip); Record[] records = new Lookup(addr, Type.PTR).run(); if (records == null) { throw new UnknownHostException(addr); } PTRRecord ptr = (PTRRecord) records[0]; return ptr.getTarget().toString(); } catch (TextParseException e) { throw new UnknownHostException(e.getMessage()); } } }
/** * Convert a Name to a String * @return The representation of this name as a (printable) String. */ public String toString() { return toString(false); }
String rrToString() { return singleName.toString(); }
String rrToString() { return singleName.toString(); }
public ResolvedAddress(Name name, int port, int priority) { this(name.toString(), port, priority); } public ResolvedAddress(String name, int port, int priority) {
String rrToString() { return singleName.toString(); }
@Override public String toString() { return hostname.toString(); }
String rrToString() { return singleName.toString(); }
return; String dnsQueryName = dnsMsg.getQuestion().getName().toString(true); if (!ruleDatabase.isBlocked(dnsQueryName.toLowerCase(Locale.ENGLISH))) { Log.i(TAG, "handleDnsRequest: DNS Name " + dnsQueryName + " Allowed, sending to " + destAddr);
/** Returns the address */ public InetAddress getAddress() { try { if (name == null) return InetAddress.getByAddress(address); else return InetAddress.getByAddress(name.toString(), address); } catch (UnknownHostException e) { return null; } }
void rrFromWire(DNSInput in) throws IOException { address = InetAddress.getByAddress(name.toString(), in.readByteArray(16)); }
private String convertRecordOwnerToString(Record record) { if (record == null) return null; String ownerString = record.getName().toString(); ownerString = ownerString.toLowerCase(); return ownerString; }
/** Returns the Internet address */ public InetAddress getAddress() { try { return InetAddress.getByAddress(name.toString(), toArray(addr)); } catch (UnknownHostException e) { return null; } }
private void initialize(Master master) throws IOException { m_records = new HashMap<String, List<Record>>(); for (Record rec = null; (rec = master.nextRecord()) != null;) { String name = rec.getName().toString(); List<Record> list = m_records.get(name); if (list == null) { list = new ArrayList<Record>(); m_records.put(name, list); } list.add(rec); } }
/** Returns the Internet address */ public InetAddress getAddress() { try { if (name == null) return InetAddress.getByAddress(toArray(addr)); else return InetAddress.getByAddress(name.toString(), toArray(addr)); } catch (UnknownHostException e) { return null; } }
@Test public void testReverseZoneNames() throws Exception { Configuration conf = new Configuration(); conf.set(KEY_DNS_ZONE_SUBNET, "172.26.32.0"); conf.set(KEY_DNS_ZONE_MASK, "255.255.224.0"); Name name = getRegistryDNS().getReverseZoneName(conf); assertEquals("wrong name", "26.172.in-addr.arpa.", name.toString()); }
public DBRecord(Record record, Name origin, long zoneTTL) { this.name = record.getName().relativize(origin).toString(); this.type = Type.string(record.getType()); this.dclass = DClass.string(record.getDClass()); this.content = record.rdataToString(); if(record.getTTL() == zoneTTL){ this.ttl = null; }else{ this.ttl = record.getTTL(); } }