Java Code Examples for org.xbill.DNS.DClass#IN

The following examples show how to use org.xbill.DNS.DClass#IN . 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: DNSLookupService.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Dns lookup more efficient than the INetAddress.getHostName(ip)
 *
 * @param hostIp
 * @return
 * @throws IOException
 */
public String dnsLookup(final String hostIp) {
	try {
		final Name name = ReverseMap.fromAddress(hostIp);
		final int type = Type.PTR;
		final int dclass = DClass.IN;
		final Record rec = Record.newRecord(name, type, dclass);
		final Message query = Message.newQuery(rec);

		final Message response = _resolver.send(query);

		final Record[] answers = response.getSectionArray(Section.ANSWER);
		if (answers.length > 0) {
			String ret = answers[0].rdataToString();
			if (ret.endsWith(".")) {
				ret = ret.substring(0, ret.length() - 1);
			}
			return ret;
		}
	} catch (final IOException e) {
		LOGGER.warn("Failed to resolve hostname for " + hostIp, e);
	}
	return UNKNOWN_HOST;
}
 
Example 2
Source File: DnsUpdateWriter.java    From nomulus with Apache License 2.0 6 votes vote down vote up
private RRset makeDelegationSignerSet(DomainBase domain) {
  RRset signerSet = new RRset();
  for (DelegationSignerData signerData : domain.getDsData()) {
    DSRecord dsRecord =
        new DSRecord(
            toAbsoluteName(domain.getDomainName()),
            DClass.IN,
            dnsDefaultDsTtl.getStandardSeconds(),
            signerData.getKeyTag(),
            signerData.getAlgorithm(),
            signerData.getDigestType(),
            signerData.getDigest());
    signerSet.addRR(dsRecord);
  }
  return signerSet;
}
 
Example 3
Source File: DnsUpdateWriter.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private RRset makeNameServerSet(DomainBase domain) {
  RRset nameServerSet = new RRset();
  for (String hostName : domain.loadNameserverHostNames()) {
    NSRecord record =
        new NSRecord(
            toAbsoluteName(domain.getDomainName()),
            DClass.IN,
            dnsDefaultNsTtl.getStandardSeconds(),
            toAbsoluteName(hostName));
    nameServerSet.addRR(record);
  }
  return nameServerSet;
}
 
Example 4
Source File: DnsUpdateWriter.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private RRset makeAddressSet(HostResource host) {
  RRset addressSet = new RRset();
  for (InetAddress address : host.getInetAddresses()) {
    if (address instanceof Inet4Address) {
      ARecord record =
          new ARecord(
              toAbsoluteName(host.getHostName()),
              DClass.IN,
              dnsDefaultATtl.getStandardSeconds(),
              address);
      addressSet.addRR(record);
    }
  }
  return addressSet;
}
 
Example 5
Source File: DnsUpdateWriter.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private RRset makeV6AddressSet(HostResource host) {
  RRset addressSet = new RRset();
  for (InetAddress address : host.getInetAddresses()) {
    if (address instanceof Inet6Address) {
      AAAARecord record =
          new AAAARecord(
              toAbsoluteName(host.getHostName()),
              DClass.IN,
              dnsDefaultATtl.getStandardSeconds(),
              address);
      addressSet.addRR(record);
    }
  }
  return addressSet;
}
 
Example 6
Source File: SimpleLookupFactory.java    From dns-java with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: DNSJavaService.java    From james-project with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void init() throws Exception {
    LOGGER.debug("DNSService init...");

    // If no DNS servers were configured, default to local host
    if (dnsServers.isEmpty()) {
        try {
            dnsServers.add(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException ue) {
            dnsServers.add("127.0.0.1");
        }
    }

    // Create the extended resolver...
    final String[] serversArray = dnsServers.toArray(String[]::new);

    if (LOGGER.isInfoEnabled()) {
        for (String aServersArray : serversArray) {
            LOGGER.info("DNS Server is: " + aServersArray);
        }
    }

    try {
        resolver = new ExtendedResolver(serversArray);
    } catch (UnknownHostException uhe) {
        LOGGER.error("DNS service could not be initialized.  The DNS servers specified are not recognized hosts.", uhe);
        throw uhe;
    }

    cache = new Cache(DClass.IN);
    cache.setMaxEntries(maxCacheSize);
    cache.setMaxNCache(negativeCacheTTL);

    if (setAsDNSJavaDefault) {
        Lookup.setDefaultResolver(resolver);
        Lookup.setDefaultCache(cache, DClass.IN);
        Lookup.setDefaultSearchPath(searchPaths);
        LOGGER.info("Registered cache, resolver and search paths as DNSJava defaults");
    }

    // Cache the local hostname and local address. This is needed because
    // the following issues:
    // JAMES-787
    // JAMES-302
    InetAddress addr = getLocalHost();
    localCanonicalHostName = addr.getCanonicalHostName();
    localHostName = addr.getHostName();
    localAddress = addr.getHostAddress();

    LOGGER.debug("DNSService ...init end");
}
 
Example 8
Source File: jnamed.java    From dnsjava with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addSecondaryZone(String zone, String remote)
    throws IOException, ZoneTransferException {
  Name zname = Name.fromString(zone, Name.root);
  Zone newzone = new Zone(zname, DClass.IN, remote);
  znames.put(zname, newzone);
}