Java 类org.xbill.DNS.CNAMERecord 实例源码

项目:ddns    文件:DDNS.java   
private static HashMap<String, String> getDynamicMap() {
    HashMap<String, String> dynamicMap = new HashMap<>();
    aDynamics.forEach((host, records) -> {
        StringBuilder sb = new StringBuilder();
        for (Record record : records) {
            if (record instanceof ARecord) {
                sb.append(((ARecord) record).getAddress().getHostAddress());
            } else if (record instanceof CNAMERecord) {
                sb.append(((CNAMERecord) record).getTarget().
                        toString(true).toLowerCase());
            }
            sb.append(',');
        }
        dynamicMap.put(host, sb.substring(0, Math.max(sb.length() - 1, 0)));
    });
    return dynamicMap;
}
项目:ddns    文件:DDNS.java   
private static void updateRecords(Map<String, Record[]> records,
        String host, String value, int ttl) throws IOException {
    if (value == null) {
        records.remove(host);
        return;
    }
    Name origin = new Name((host.endsWith(".") ? host : host + ".").replace('_', '-'));
    ArrayList<Record> recordList = new ArrayList<>();
    for (String s : value.split("[,;]")) {
        if (s.matches(".*[A-Z|a-z].*")) {
            CNAMERecord record = new CNAMERecord(origin, DClass.IN, ttl,
                    new Name(s.endsWith(".") ? s : s + "."));
            recordList.add(record);
            continue;
        }
        String[] ss = s.split("\\.");
        if (ss.length < 4) {
            continue;
        }
        byte[] ip = new byte[4];
        for (int i = 0; i < 4; i ++) {
            ip[i] = (byte) Numbers.parseInt(ss[i]);
        }
        recordList.add(new ARecord(origin, DClass.IN,
                ttl, InetAddress.getByAddress(ip)));
    }
    records.put(host, recordList.toArray(EMPTY_RECORDS));
}
项目:onomate    文件:CreateCNameRecordTests.java   
@Test
public void canResolveRecord() throws Exception {
    AcceptanceTestRunner runner = new AcceptanceTestRunner();
    runner.runUngarded(new AcceptanceScenario() {

        public void run(WebDriver driver, String deployedURL) throws Exception {
            int id = new SecureRandom().nextInt();
            final String systemTestBase = "system-tests.onomate.test";
            final String soaBase = "soa-" + id +"."+ systemTestBase;
            final String ns = "ns." + soaBase;
            final String contactName = "admin." + soaBase;
            final String aTestRecordHost = "record."+soaBase;
            final String aRealTestRecord = soaBase;

            OnomateAssembly assembly = new OnomateAssembly(driver, deployedURL);
            OnomateAssembly.Dashboard board = assembly.gotoLanding().authenticate().newAuthority(soaBase, ns, contactName);
            board.authorityByZone(soaBase).details().createRecord(aTestRecordHost, OnomateAssembly.RecordType.CNAME, aRealTestRecord);

            Options.set("verbose");

            SimpleResolver resolver = new SimpleResolver();
            resolver.setAddress(InetAddress.getLocalHost());
            resolver.setPort(9101);

            Record query = Record.newRecord(Name.fromString(aTestRecordHost + "."), Type.CNAME, DClass.IN);
            Message question = Message.newQuery(query);
            Message response = resolver.send(question);
            Record responses[] = response.getSectionArray(Section.ANSWER);
            CNAMERecord record = ((CNAMERecord) responses[0]);
            assertEquals(record.getName().toString(), aTestRecordHost+ ".");
            assertEquals(record.getTarget().toString(), aRealTestRecord + ".");
        }
    });
}
项目:wagon-git    文件:GitHubPagesWagon.java   
/**
 * Gets the CNAME record for the host.
 *
 * @param host
 *            host
 * @return CNAME record may return null if not found.
 * @throws TextParseException
 */
private String getCnameForHost(final String host) throws TextParseException {

    final Lookup lookup = new Lookup(host, Type.CNAME);
    lookup.run();
    if (lookup.getAnswers().length == 0) {
        LOG.log(Level.SEVERE, "unableToFindCNAME", new Object[] {
            host
        });
        return null;
    }
    return ((CNAMERecord) lookup.getAnswers()[0]).getTarget().toString();
}
项目:wagon-git    文件:NetworkLookupTests.java   
/**
 * Tests the CNAME lookup functionality of dnsjava.
 */
@Test
public void testCNameLookup() throws Exception {

    final Lookup lookup = new Lookup("www.trajano.net", Type.CNAME);
    lookup.run();
    assertEquals("trajano.net.", ((CNAMERecord) lookup.run()[0]).getTarget()
        .toString());
}
项目:yeti    文件:TldController.java   
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;
        }
    }
}
项目:yeti    文件:DNS.java   
public static CNAMERecord getCNAMERecord(String hostName) {
    return null;
}
项目:yeti    文件:DataAPI.java   
public CNAMERecord getCNAMERecord(String hostName) {
    return null;
}
项目:dnssecjava    文件:ValidatingResolver.java   
private boolean validateAnswerAndGetWildcards(SMessage response, int qtype, Map<Name, Name> wcs) {
    // validate the ANSWER section - this will be the answer itself
    DNAMERecord dname = null;
    for (SRRset set : response.getSectionRRsets(Section.ANSWER)) {
        // Validate the CNAME following a (validated) DNAME is correctly
        // synthesized.
        if (set.getType() == Type.CNAME && dname != null) {
            if (set.size() > 1) {
                response.setBogus(R.get("failed.synthesize.multiple"));
                return false;
            }

            CNAMERecord cname = (CNAMERecord)set.first();
            try {
                Name expected = Name.concatenate(cname.getName().relativize(dname.getName()), dname.getTarget());
                if (!expected.equals(cname.getTarget())) {
                    response.setBogus(R.get("failed.synthesize.nomatch", cname.getTarget(), expected));
                    return false;
                }
            }
            catch (NameTooLongException e) {
                response.setBogus(R.get("failed.synthesize.toolong"));
                return false;
            }

            set.setSecurityStatus(SecurityStatus.SECURE);
            dname = null;
            continue;
        }

        // Verify the answer rrset.
        KeyEntry ke = this.prepareFindKey(set);
        if (!this.processKeyValidate(response, set.getSignerName(), ke)) {
            return false;
        }

        SecurityStatus status = this.valUtils.verifySRRset(set, ke.getRRset());
        // If the answer rrset failed to validate, then this message is BAD
        if (status != SecurityStatus.SECURE) {
            response.setBogus(R.get("failed.answer.positive", set));
            return false;
        }

        // Check to see if the rrset is the result of a wildcard expansion.
        // If so, an additional check will need to be made in the authority
        // section.
        Name wc = null;
        try {
            wc = ValUtils.rrsetWildcard(set);
        }
        catch (RuntimeException ex) {
            response.setBogus(R.get(ex.getMessage(), set.getName()));
            return false;
        }

        if (wc != null) {
            // RFC 4592, Section 4.4 does not allow wildcarded DNAMEs
            if (set.getType() == Type.DNAME) {
                response.setBogus(R.get("failed.dname.wildcard", set.getName()));
                return false;
            }

            wcs.put(set.getName(), wc);
        }

        // Notice a DNAME that should be followed by an unsigned CNAME.
        if (qtype != Type.DNAME && set.getType() == Type.DNAME) {
            dname = (DNAMERecord)set.first();
        }
    }

    return true;
}