org.xbill.DNS.Type Java Examples

The following examples show how to use org.xbill.DNS.Type. 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: GoogleResolverCheck.java    From entrada with GNU General Public License v3.0 7 votes vote down vote up
@Override
protected List<String> fetch() {

  try {
    Resolver resolver = new SimpleResolver();
    // dns resolvers may take a long time to return a response.
    resolver.setTimeout(timeout);
    Lookup l =
        new Lookup(StringUtils.endsWith(hostname, ".") ? hostname : hostname + ".", Type.TXT);
    // always make sure the cache is empty
    l.setCache(new Cache());
    l.setResolver(resolver);
    Record[] records = l.run();
    if (records != null && records.length > 0) {
      return parse(records[0]);
    }
  } catch (Exception e) {
    log.error("Problem while adding Google resolvers, continue without", e);
  }

  log.error("No Google resolver addresses found");
  return Collections.emptyList();
}
 
Example #2
Source File: DnsUpdateWriterTest.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishDomainCreate_publishesNameServers() throws Exception {
  HostResource host1 = persistActiveHost("ns1.example.tld");
  HostResource host2 = persistActiveHost("ns2.example.tld");
  DomainBase domain =
      persistActiveDomain("example.tld")
          .asBuilder()
          .setNameservers(ImmutableSet.of(host1.createVKey(), host2.createVKey()))
          .build();
  persistResource(domain);

  writer.publishDomain("example.tld");
  writer.commit();

  verify(mockResolver).send(updateCaptor.capture());
  Update update = updateCaptor.getValue();
  assertThatUpdatedZoneIs(update, "tld.");
  assertThatUpdateDeletes(update, "example.tld.", Type.ANY);
  assertThatUpdateAdds(update, "example.tld.", Type.NS, "ns1.example.tld.", "ns2.example.tld.");
  assertThatTotalUpdateSetsIs(update, 2); // The delete and NS sets
}
 
Example #3
Source File: DNSSECVerifier.java    From androdns with Apache License 2.0 6 votes vote down vote up
public void learnDNSSECKeysFromRRSETs(RRset[] rrsets){
    Iterator it;
    int i;

    for (i = 0; i < rrsets.length; i++) {
        RRset rrset = rrsets[i];
        if (rrset.getType()!=Type.DNSKEY){
            continue;
        }
        it = rrset.rrs();

        while (it.hasNext()) {
            DNSKEYRecord r = (DNSKEYRecord) it.next();
            addDNSKEY(r);
        }


    }

}
 
Example #4
Source File: DNS.java    From yeti with MIT License 6 votes vote down vote up
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 #5
Source File: NetworkTools.java    From yeti with MIT License 6 votes vote down vote up
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 #6
Source File: DataAPI.java    From yeti with MIT License 6 votes vote down vote up
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 #7
Source File: Helperfunctions.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
public static String reverseDNSLookup(final InetAddress adr)
{
    try
    {
        final Name name = ReverseMap.fromAddress(adr);
        
        final Lookup lookup = new Lookup(name, Type.PTR);
        lookup.setResolver(new SimpleResolver());
        lookup.setCache(null);
        final Record[] records = lookup.run();
        if (lookup.getResult() == Lookup.SUCCESSFUL)
            for (final Record record : records)
                if (record instanceof PTRRecord)
                {
                    final PTRRecord ptr = (PTRRecord) record;
                    return ptr.getTarget().toString();
                }
    }
    catch (final Exception e)
    {
    }
    return null;
}
 
Example #8
Source File: DnsJavaResolver.java    From browserup-proxy with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<InetAddress> resolveRemapped(String remappedHost) {
    // special case for IP literals: return the InetAddress without doing a dnsjava lookup. dnsjava seems to handle ipv4 literals
    // reasonably well, but does not handle ipv6 literals (with or without [] brackets) correctly.
    // note this does not work properly for ipv6 literals with a scope identifier, which is a known issue for InetAddresses.isInetAddress().
    // (dnsjava also handles the situation incorrectly)
    if (InetAddresses.isInetAddress(remappedHost)) {
        return Collections.singletonList(InetAddresses.forString(remappedHost));
    }

    // retrieve IPv4 addresses, then retrieve IPv6 addresses only if no IPv4 addresses are found. the current implementation always uses the
    // first returned address, so there is no need to look for IPv6 addresses if an IPv4 address is found.
    Collection<InetAddress> ipv4addresses = resolveHostByType(remappedHost, Type.A);

    if (!ipv4addresses.isEmpty()) {
        return ipv4addresses;
    } else {
        return resolveHostByType(remappedHost, Type.AAAA);
    }
}
 
Example #9
Source File: Utils.java    From Maying with Apache License 2.0 6 votes vote down vote up
public static String resolve(String host, boolean enableIPv6) {
    String address = null;
    if (enableIPv6 && isIPv6Support()) {
        address = resolve(host, Type.AAAA);
        if (!TextUtils.isEmpty(address)) {
            return address;
        }
    }

    address = resolve(host, Type.A);
    if (!TextUtils.isEmpty(address)) {
        return address;
    }

    address = resolve(host);
    if (!TextUtils.isEmpty(address)) {
        return address;
    }

    return null;
}
 
Example #10
Source File: DnsJavaResolver.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public Collection<InetAddress> resolveRemapped(String remappedHost) {
    // special case for IP literals: return the InetAddress without doing a dnsjava lookup. dnsjava seems to handle ipv4 literals
    // reasonably well, but does not handle ipv6 literals (with or without [] brackets) correctly.
    // note this does not work properly for ipv6 literals with a scope identifier, which is a known issue for InetAddresses.isInetAddress().
    // (dnsjava also handles the situation incorrectly)
    if (InetAddresses.isInetAddress(remappedHost)) {
        return Collections.singletonList(InetAddresses.forString(remappedHost));
    }

    // retrieve IPv4 addresses, then retrieve IPv6 addresses only if no IPv4 addresses are found. the current implementation always uses the
    // first returned address, so there is no need to look for IPv6 addresses if an IPv4 address is found.
    Collection<InetAddress> ipv4addresses = resolveHostByType(remappedHost, Type.A);

    if (!ipv4addresses.isEmpty()) {
        return ipv4addresses;
    } else {
        return resolveHostByType(remappedHost, Type.AAAA);
    }
}
 
Example #11
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 #12
Source File: DnsIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testDnsProducer() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .to("dns:lookup");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Record[] record = producer.requestBodyAndHeader("direct:start", null, DnsConstants.DNS_NAME, "redhat.com", Record[].class);

        Assert.assertEquals("redhat.com.", record[0].getName().toString());
        Assert.assertEquals(Type.A, record[0].getType());
    } catch (CamelExecutionException ex) {
        Throwable cause = ex.getCause();
        Assert.assertEquals("network error", cause.getMessage());
    } finally {
        camelctx.close();
    }
}
 
Example #13
Source File: DNS.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Query a text record for the given domain from DNS
 * 
 * @param domain the domain to lookup the DNS for a text record
 * @return       the text record content, if found, null otherwise
 */
@SuppressWarnings ("unchecked")
public String queryText (String domain) {
	String		rc = null;
	Record[]	r = query (domain, Type.TXT);
	
	if (r != null) {
		rc = "";
		for (int n = 0; n < r.length; ++n) {
			List <String>	answ = ((TXTRecord) r[n]).getStrings ();
			
			for (int m = 0; m < answ.size (); ++m) {
				String	s = answ.get (m);
				
				if ((s != null) && (s.length () > 0)) {
					rc += s;
				}
			}
		}
	}
	return rc;
}
 
Example #14
Source File: DnsJavaResolver.java    From Dream-Catcher with MIT License 6 votes vote down vote up
@Override
public Collection<InetAddress> resolveRemapped(String remappedHost) {
    // special case for IP literals: return the InetAddress without doing a dnsjava lookup. dnsjava seems to handle ipv4 literals
    // reasonably well, but does not handle ipv6 literals (with or without [] brackets) correctly.
    // note this does not work properly for ipv6 literals with a scope identifier, which is a known issue for InetAddresses.isInetAddress().
    // (dnsjava also handles the situation incorrectly)
    if (InetAddresses.isInetAddress(remappedHost)) {
        return Collections.singletonList(InetAddresses.forString(remappedHost));
    }

    // retrieve IPv4 addresses, then retrieve IPv6 addresses only if no IPv4 addresses are found. the current implementation always uses the
    // first returned address, so there is no need to look for IPv6 addresses if an IPv4 address is found.
    Collection<InetAddress> ipv4addresses = resolveHostByType(remappedHost, Type.A);

    if (!ipv4addresses.isEmpty()) {
        return ipv4addresses;
    } else {
        return resolveHostByType(remappedHost, Type.AAAA);
    }
}
 
Example #15
Source File: DnsJavaResolver.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
public Collection<InetAddress> resolveRemapped(String remappedHost) {
    // special case for IP literals: return the InetAddress without doing a dnsjava lookup. dnsjava seems to handle ipv4 literals
    // reasonably well, but does not handle ipv6 literals (with or without [] brackets) correctly.
    // note this does not work properly for ipv6 literals with a scope identifier, which is a known issue for InetAddresses.isInetAddress().
    // (dnsjava also handles the situation incorrectly)
    if (InetAddresses.isInetAddress(remappedHost)) {
        return Collections.singletonList(InetAddresses.forString(remappedHost));
    }

    // retrieve IPv4 addresses, then retrieve IPv6 addresses only if no IPv4 addresses are found. the current implementation always uses the
    // first returned address, so there is no need to look for IPv6 addresses if an IPv4 address is found.
    Collection<InetAddress> ipv4addresses = resolveHostByType(remappedHost, Type.A);

    if (!ipv4addresses.isEmpty()) {
        return ipv4addresses;
    } else {
        return resolveHostByType(remappedHost, Type.AAAA);
    }
}
 
Example #16
Source File: DnsUpdateWriter.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/**
 * Publish the domain, while keeping tracking of which host refresh quest triggered this domain
 * refresh. Delete the requesting host in addition to all subordinate hosts.
 *
 * @param domainName the fully qualified domain name, with no trailing dot
 * @param requestingHostName the fully qualified host name, with no trailing dot, that triggers
 *     this domain refresh request
 */
private void publishDomain(String domainName, String requestingHostName) {
  Optional<DomainBase> domainOptional =
      loadByForeignKey(DomainBase.class, domainName, clock.nowUtc());
  update.delete(toAbsoluteName(domainName), Type.ANY);
  // If the domain is now deleted, then don't update DNS for it.
  if (domainOptional.isPresent()) {
    DomainBase domain = domainOptional.get();
    // As long as the domain exists, orphan glues should be cleaned.
    deleteSubordinateHostAddressSet(domain, requestingHostName, update);
    if (domain.shouldPublishToDns()) {
      addInBailiwickNameServerSet(domain, update);
      update.add(makeNameServerSet(domain));
      update.add(makeDelegationSignerSet(domain));
    }
  }
}
 
Example #17
Source File: ForwardLookupHelper.java    From yeti with MIT License 6 votes vote down vote up
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 #18
Source File: ForwardLookupHelper.java    From yeti with MIT License 6 votes vote down vote up
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 #19
Source File: DnsUpdateWriterTest.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishDomainCreate_publishesDelegationSigner() throws Exception {
  DomainBase domain =
      persistActiveDomain("example.tld")
          .asBuilder()
          .setNameservers(ImmutableSet.of(persistActiveHost("ns1.example.tld").createVKey()))
          .setDsData(
              ImmutableSet.of(
                  DelegationSignerData.create(1, 3, 1, base16().decode("0123456789ABCDEF"))))
          .build();
  persistResource(domain);

  writer.publishDomain("example.tld");
  writer.commit();

  verify(mockResolver).send(updateCaptor.capture());
  Update update = updateCaptor.getValue();
  assertThatUpdatedZoneIs(update, "tld.");
  assertThatUpdateDeletes(update, "example.tld.", Type.ANY);
  assertThatUpdateAdds(update, "example.tld.", Type.NS, "ns1.example.tld.");
  assertThatUpdateAdds(update, "example.tld.", Type.DS, "1 3 1 0123456789ABCDEF");
  assertThatTotalUpdateSetsIs(update, 3); // The delete, the NS, and DS sets
}
 
Example #20
Source File: DnsUpdateWriterTest.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishDomainWhenNotActive_removesDnsRecords() throws Exception {
  DomainBase domain =
      persistActiveDomain("example.tld")
          .asBuilder()
          .addStatusValue(StatusValue.SERVER_HOLD)
          .setNameservers(ImmutableSet.of(persistActiveHost("ns1.example.tld").createVKey()))
          .build();
  persistResource(domain);

  writer.publishDomain("example.tld");
  writer.commit();

  verify(mockResolver).send(updateCaptor.capture());
  Update update = updateCaptor.getValue();
  assertThatUpdatedZoneIs(update, "tld.");
  assertThatUpdateDeletes(update, "example.tld.", Type.ANY);
  assertThatTotalUpdateSetsIs(update, 1); // Just the delete set
}
 
Example #21
Source File: DnsUpdateWriterTest.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishHostDelete_removesGlueRecords() throws Exception {
  persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
  persistResource(
      persistActiveDomain("example.tld")
          .asBuilder()
          .setNameservers(ImmutableSet.of(persistActiveHost("ns1.example.com").createVKey()))
          .build());

  writer.publishHost("ns1.example.tld");
  writer.commit();

  verify(mockResolver).send(updateCaptor.capture());
  Update update = updateCaptor.getValue();
  assertThatUpdatedZoneIs(update, "tld.");
  assertThatUpdateDeletes(update, "example.tld.", Type.ANY);
  assertThatUpdateDeletes(update, "ns1.example.tld.", Type.ANY);
  assertThatUpdateAdds(update, "example.tld.", Type.NS, "ns1.example.com.");
  assertThatTotalUpdateSetsIs(update, 3);
}
 
Example #22
Source File: DnsMessageTransportTest.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSentMessageTooLongThrowsException() throws Exception {
  Update oversize = new Update(Name.fromString("tld", Name.root));
  for (int i = 0; i < 2000; i++) {
    oversize.add(
        ARecord.newRecord(
            Name.fromString("test-extremely-long-name-" + i + ".tld", Name.root),
            Type.A,
            DClass.IN));
  }
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  when(mockSocket.getOutputStream()).thenReturn(outputStream);
  IllegalArgumentException thrown =
      assertThrows(IllegalArgumentException.class, () -> resolver.send(oversize));
  assertThat(thrown).hasMessageThat().contains("message larger than maximum");
}
 
Example #23
Source File: DNSJavaService.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public InetAddress getByName(String host) throws UnknownHostException {
    TimeMetric timeMetric = metricFactory.timer("getByName");
    String name = allowIPLiteral(host);

    try {
        // Check if its local
        if (name.equalsIgnoreCase(localHostName) || name.equalsIgnoreCase(localCanonicalHostName) || name.equals(localAddress)) {
            return getLocalHost();
        }

        return org.xbill.DNS.Address.getByAddress(name);
    } catch (UnknownHostException e) {
        Record[] records = lookupNoException(name, Type.A, "A");

        if (records != null && records.length >= 1) {
            ARecord a = (ARecord) records[0];
            return InetAddress.getByAddress(name, a.getAddress().getAddress());
        } else {
            throw e;
        }
    } finally {
        timeMetric.stopAndPublish();
    }
}
 
Example #24
Source File: IpAddressUtil.java    From megatron-java with Apache License 2.0 6 votes vote down vote up
private static String reverseDnsLookupUsingDnsJavaSimpleResolver(long ipAddress) throws IOException {
    String result = null;
    byte[] address = convertLongAddressToBuf(ipAddress);
    Name name = ReverseMap.fromAddress(InetAddress.getByAddress(address));
    Record record = Record.newRecord(name, Type.PTR, DClass.IN);
    Message query = Message.newQuery(record);
    Message response = simpleResolver.send(query);
    Record[] answers = response.getSectionArray(Section.ANSWER);
    if (answers.length != 0) {
        // If PTR-record exists this will be at index 1 or above (more than one PTR-record may exist)
        Record answer = (answers.length > 1) ? answers[1] : answers[0];  
        result = answer.rdataToString();
        // remove trailing "."
        result = result.endsWith(".") ? result.substring(0, result.length() - 1) : result;
    } else {
        throw new IOException("Empty DNS response.");
    }
    return result;
}
 
Example #25
Source File: DNSJavaService.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<String> findTXTRecords(String hostname) {
    TimeMetric timeMetric = metricFactory.timer("findTXTRecords");
    List<String> txtR = new ArrayList<>();
    Record[] records = lookupNoException(hostname, Type.TXT, "TXT");

    try {
        if (records != null) {
            for (Record record : records) {
                TXTRecord txt = (TXTRecord) record;
                txtR.add(txt.rdataToString());
            }

        }
        return txtR;
    } finally {
        timeMetric.stopAndPublish();
    }
}
 
Example #26
Source File: DNSJavaService.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public String getHostName(InetAddress addr) {
    TimeMetric timeMetric = metricFactory.timer("getHostName");
    String result;
    Name name = ReverseMap.fromAddress(addr);
    Record[] records = lookupNoException(name.toString(), Type.PTR, "PTR");

    try {
        if (records == null) {
            result = addr.getHostAddress();
        } else {
            PTRRecord ptr = (PTRRecord) records[0];
            result = ptr.getTarget().toString();
        }
        return result;
    } finally {
        timeMetric.stopAndPublish();
    }
}
 
Example #27
Source File: update.java    From dnsjava with BSD 2-Clause "Simplified" License 6 votes vote down vote up
void doProhibit(Tokenizer st) throws IOException {
  Tokenizer.Token token;
  Name name;
  Record record;
  int type;

  name = st.getName(zone);
  token = st.get();
  if (token.isString()) {
    if ((type = Type.value(token.value)) < 0) {
      throw new IOException("Invalid type: " + token.value);
    }
  } else {
    type = Type.ANY;
  }
  record = Record.newRecord(name, type, DClass.NONE, 0);
  query.addRecord(record, Section.PREREQ);
  print(record);
}
 
Example #28
Source File: XBillDnsSrvResolverTest.java    From dns-java with Apache License 2.0 6 votes vote down vote up
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 #29
Source File: update.java    From dnsjava with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Record parseRR(Tokenizer st, int classValue, long TTLValue) throws IOException {
  Name name = st.getName(zone);
  long ttl;
  int type;

  String s = st.getString();

  try {
    ttl = TTL.parseTTL(s);
    s = st.getString();
  } catch (NumberFormatException e) {
    ttl = TTLValue;
  }

  if (DClass.value(s) >= 0) {
    classValue = DClass.value(s);
    s = st.getString();
  }

  if ((type = Type.value(s)) < 0) {
    throw new IOException("Invalid type: " + s);
  }

  return Record.fromString(name, type, classValue, ttl, st, zone);
}
 
Example #30
Source File: lookup.java    From dnsjava with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  int type = Type.A;
  int start = 0;
  if (args.length > 2 && args[0].equals("-t")) {
    type = Type.value(args[1]);
    if (type < 0) {
      throw new IllegalArgumentException("invalid type");
    }
    start = 2;
  }
  for (int i = start; i < args.length; i++) {
    Lookup l = new Lookup(args[i], type);
    l.run();
    printAnswer(args[i], l);
  }
}