org.xbill.DNS.Message.newQuery()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(254)

本文整理了Java中org.xbill.DNS.Message.newQuery()方法的一些代码示例,展示了Message.newQuery()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.newQuery()方法的具体详情如下:
包路径:org.xbill.DNS.Message
类名称:Message
方法名:newQuery

Message.newQuery介绍

暂无

代码示例

代码示例来源:origin: julian-klode/dns66

@Test
public void testDnsQuery() throws Exception {
  Message message = Message.newQuery(new ARecord(new Name("notblocked.example.com."),
      0x01,
      3600,

代码示例来源:origin: org.apache.whirr/whirr-core

Message response = resolver.send(newQuery(record));

代码示例来源:origin: apache/attic-whirr

Message response = resolver.send(newQuery(record));

代码示例来源:origin: org.apache.james/apache-jspf

private Message makeQuery(DNSRequest request, int id) throws TextParseException {
    Name name = Name.fromString(request.getHostname(), Name.root);
    
    int type;
    switch (request.getRecordType()) {
      case DNSRequest.A: type = Type.A; break;
      case DNSRequest.AAAA: type = Type.AAAA; break;
      case DNSRequest.MX: type = Type.MX; break;
      case DNSRequest.PTR: type = Type.PTR; break;
      case DNSRequest.SPF: type = Type.SPF; break;
      case DNSRequest.TXT: type = Type.TXT; break;
      default: 
        throw new UnsupportedOperationException("Unknown query type: "+request.getRecordType());
    }
    
    Record question = Record.newRecord(name, type, DClass.ANY);
    Message query = Message.newQuery(question);
    query.getHeader().setID(id);
    return query;
  }
}

代码示例来源:origin: org.apache.james.jspf/apache-jspf-resolver

private Message makeQuery(DNSRequest request, int id) throws TextParseException {
    Name name = Name.fromString(request.getHostname(), Name.root);
    
    int type;
    switch (request.getRecordType()) {
      case DNSRequest.A: type = Type.A; break;
      case DNSRequest.AAAA: type = Type.AAAA; break;
      case DNSRequest.MX: type = Type.MX; break;
      case DNSRequest.PTR: type = Type.PTR; break;
      case DNSRequest.SPF: type = Type.SPF; break;
      case DNSRequest.TXT: type = Type.TXT; break;
      default: 
        throw new UnsupportedOperationException("Unknown query type: "+request.getRecordType());
    }
    
    Record question = Record.newRecord(name, type, DClass.ANY);
    Message query = Message.newQuery(question);
    query.getHeader().setID(id);
    return query;
  }
}

代码示例来源:origin: julian-klode/dns66

@Test
public void testBlockedDnsQuery() throws Exception {
  Message message = Message.newQuery(new ARecord(new Name("blocked.example.com."),
      0x01,
      3600,

代码示例来源:origin: DSpace/DSpace

Message query = Message.newQuery(rec);
Message response = res.send(query);

代码示例来源:origin: dnsjava/dnsjava

Message newQuery = Message.newQuery(rec);
if (res == null)
  res = new SimpleResolver(server);

代码示例来源:origin: net.sf.dnsjava-osgi/dnsjava-osgi

Message query = Message.newQuery(question);
Message response = null;
try {

代码示例来源:origin: org.dspace/dspace-stats

public static String reverseDns(String hostIp) throws IOException {
     Resolver res = new ExtendedResolver();
          // set the timeout, defaults to 200 milliseconds
     int timeout = ConfigurationManager.getIntProperty("solr-statistics", "resolver.timeout", 200);
     res.setTimeout(0, timeout);

     Name name = ReverseMap.fromAddress(hostIp);
     int type = Type.PTR;
     int dclass = DClass.IN;
     Record rec = Record.newRecord(name, type, dclass);
     Message query = Message.newQuery(rec);
     Message response = res.send(query);

     Record[] answers = response.getSectionArray(Section.ANSWER);
     if (answers.length == 0)
     {
       return hostIp;
     }
     else
     {
       return answers[0].rdataToString();
     }
  }
}

代码示例来源:origin: DSpace/DSpace

/**
 * Resolve an IP address to a host name.
 *
 * @param hostIp dotted decimal IPv4 address.
 * @return name if resolved, or the address.
 * @throws IOException from infrastructure.
 */
public static String reverseDns(String hostIp) throws IOException {
  Resolver res = new ExtendedResolver();
  // set the timeout, defaults to 200 milliseconds
  int timeout = ConfigurationManager.getIntProperty("usage-statistics", "resolver.timeout", 200);
  res.setTimeout(0, timeout);
  Name name = ReverseMap.fromAddress(hostIp);
  int type = Type.PTR;
  int dclass = DClass.IN;
  Record rec = Record.newRecord(name, type, dclass);
  Message query = Message.newQuery(rec);
  Message response = res.send(query);
  Record[] answers = response.getSectionArray(Section.ANSWER);
  if (answers.length == 0) {
    return hostIp;
  } else {
    return answers[0].rdataToString();
  }
}

代码示例来源:origin: julian-klode/dns66

@Test
public void testBlockedInet6DnsQuery() throws Exception {
  Message message = Message.newQuery(new ARecord(new Name("blocked.example.com."),
      0x01,
      3600,

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

@Test
public void testContainerRegistrationPersistanceAbsent() throws Exception {
 ServiceRecord record = marshal.fromBytes("somepath",
   CONTAINER_RECORD_YARN_PERSISTANCE_ABSENT.getBytes());
 registryDNS.register(
   "/registry/users/root/services/org-apache-slider/test1/components/"
     + "ctr-e50-1451931954322-0016-01-000003",
    record);
 Name name =
   Name.fromString("ctr-e50-1451931954322-0016-01-000002.dev.test.");
 Record question = Record.newRecord(name, Type.A, DClass.IN);
 Message query = Message.newQuery(question);
 byte[] responseBytes = registryDNS.generateReply(query, null);
 Message response = new Message(responseBytes);
 assertEquals("Excepting NXDOMAIN as Record must not have regsisterd wrong",
   Rcode.NXDOMAIN, response.getRcode());
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

/**
 * Create a query to forward to the primary DNS server (if configured).
 * NOTE:  Experimental
 *
 * @param query the inbound query.
 * @return the query to forward to the primary server.
 * @throws NameTooLongException
 * @throws TextParseException if query creation fails.
 */
private Message createPrimaryQuery(Message query)
  throws NameTooLongException, TextParseException {
 Name name = query.getQuestion().getName();
 if (name.labels() > 0 && name.labels() <= 2) {
  // short relative or absolute name.  this code may not be necessary -
  // OS resolution utilities probably append the search paths defined
  // in resolv.conf prior to the lookup
  int id = query.getHeader().getID();
  String queryName = name.getLabelString(0);
  Name qualifiedName = Name.concatenate(Name.fromString(queryName),
    Name.fromString(domainName));
  LOG.info("Received query {}.  Forwarding query {}", name, qualifiedName);
  Record question = Record.newRecord(qualifiedName,
    query.getQuestion().getType(),
    query.getQuestion().getDClass());
  query = Message.newQuery(question);
  query.getHeader().setID(id);
 }
 return query;
}

代码示例来源:origin: github/elasticsearch-srv-discovery

@Override
  public Message send(Message query) throws IOException {
    final String HOSTNAME = "localhost.";
    if (query.getQuestion().getName().toString().equals(Constants.TEST_QUERY)) {
      Record question = Record.newRecord(query.getQuestion().getName(), Type.SRV, DClass.IN);
      Message queryMessage = Message.newQuery(question);
      Message result = new Message();
      result.setHeader(queryMessage.getHeader());
      result.addRecord(question, Section.QUESTION);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_0_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_1_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_2_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_3_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_4_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      return result;
    }
    if (query.getQuestion().getName().toString().equals(HOSTNAME)) {
      Record question = Record.newRecord(query.getQuestion().getName(), Type.A, DClass.IN);
      Message queryMessage = Message.newQuery(question);
      Message result = new Message();
      result.setHeader(queryMessage.getHeader());
      result.addRecord(question, Section.QUESTION);
      result.addRecord(new ARecord(query.getQuestion().getName(), DClass.IN, 1, InetAddress.getLoopbackAddress()), Section.ANSWER);
      return result;
    }
    throw new IllegalArgumentException("Unknown test query: " + query.getQuestion().getName().toString());
  }
};

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

@Test
public void testNoContainerIP() throws Exception {
 ServiceRecord record = getMarshal().fromBytes("somepath",
   CONTAINER_RECORD_NO_IP.getBytes());
 getRegistryDNS().register(
   "/registry/users/root/services/org-apache-slider/test1/components/"
     + "ctr-e50-1451931954322-0016-01-000002",
   record);
 // start assessing whether correct records are available
 Name name =
   Name.fromString("ctr-e50-1451931954322-0016-01-000002.dev.test.");
 Record question = Record.newRecord(name, Type.A, DClass.IN);
 Message query = Message.newQuery(question);
 byte[] responseBytes = getRegistryDNS().generateReply(query, null);
 Message response = new Message(responseBytes);
 assertEquals("wrong status", Rcode.NXDOMAIN, response.getRcode());
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

@Test
public void testMissingReverseLookup() throws Exception {
 ServiceRecord record = getMarshal().fromBytes("somepath",
   CONTAINER_RECORD.getBytes());
 getRegistryDNS().register(
   "/registry/users/root/services/org-apache-slider/test1/components/"
     + "ctr-e50-1451931954322-0016-01-000002",
   record);
 // start assessing whether correct records are available
 Name name = Name.fromString("19.1.17.172.in-addr.arpa.");
 Record question = Record.newRecord(name, Type.PTR, DClass.IN);
 Message query = Message.newQuery(question);
 OPTRecord optRecord = new OPTRecord(4096, 0, 0, Flags.DO, null);
 query.addRecord(optRecord, Section.ADDITIONAL);
 byte[] responseBytes = getRegistryDNS().generateReply(query, null);
 Message response = new Message(responseBytes);
 assertEquals("Missing record should be: ", Rcode.NXDOMAIN,
   response.getRcode());
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

Record[] assertDNSQueryNotNull(String lookup, int type, int answerCount)
  throws IOException {
 Name name = Name.fromString(lookup);
 Record question = Record.newRecord(name, type, DClass.IN);
 Message query = Message.newQuery(question);
 OPTRecord optRecord = new OPTRecord(4096, 0, 0, Flags.DO, null);
 query.addRecord(optRecord, Section.ADDITIONAL);
 byte[] responseBytes = getRegistryDNS().generateReply(query, null);
 Message response = new Message(responseBytes);
 assertEquals("not successful", Rcode.NOERROR, response.getRcode());
 assertNotNull("Null response", response);
 assertEquals("Questions do not match", query.getQuestion(),
   response.getQuestion());
 Record[] recs = response.getSectionArray(Section.ANSWER);
 assertEquals(answerCount, recs.length);
 assertEquals(recs[0].getType(), type);
 return recs;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

Message query = Message.newQuery(question);

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

Record[] assertDNSQuery(String lookup, int type, int numRecs)
  throws IOException {
 Name name = Name.fromString(lookup);
 Record question = Record.newRecord(name, type, DClass.IN);
 Message query = Message.newQuery(question);
 OPTRecord optRecord = new OPTRecord(4096, 0, 0, Flags.DO, null);
 query.addRecord(optRecord, Section.ADDITIONAL);
 byte[] responseBytes = getRegistryDNS().generateReply(query, null);
 Message response = new Message(responseBytes);
 assertEquals("not successful", Rcode.NOERROR, response.getRcode());
 assertNotNull("Null response", response);
 assertEquals("Questions do not match", query.getQuestion(),
   response.getQuestion());
 Record[] recs = response.getSectionArray(Section.ANSWER);
 assertEquals("wrong number of answer records",
   isSecure() ? numRecs * 2 : numRecs, recs.length);
 if (isSecure()) {
  boolean signed = false;
  for (Record record : recs) {
   signed = record.getType() == Type.RRSIG;
   if (signed) {
    break;
   }
  }
  assertTrue("No signatures found", signed);
 }
 return recs;
}

相关文章