当前位置: 首页>>代码示例>>Java>>正文


Java Message类代码示例

本文整理汇总了Java中org.xbill.DNS.Message的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Message类属于org.xbill.DNS包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.xbill.DNS.Message; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	try (DatagramSocket socket = new DatagramSocket()) {
		Message message = new Message();
		Header header = message.getHeader();
		header.setOpcode(Opcode.QUERY);
		header.setID(1);
		header.setRcode(Rcode.NOERROR);
		header.setFlag(Flags.RD);
		message.addRecord(Record.newRecord(new Name("www.xqbase.com."), Type.A, DClass.IN), Section.QUESTION);
		byte[] data = message.toWire();
		DatagramPacket packet = new DatagramPacket(data, data.length, new InetSocketAddress("localhost", 53));
		socket.send(packet);
		data = new byte[65536];
		packet = new DatagramPacket(data, data.length);
		socket.setSoTimeout(2000);
		socket.receive(packet);
		Message response = new Message(Bytes.left(data, packet.getLength()));
		System.out.println(response);
	}
}
 
开发者ID:xqbase,项目名称:ddns,代码行数:21,代码来源:TestDatagram.java

示例2: run

import org.xbill.DNS.Message; //导入依赖的package包/类
@Override
public void run() {
    while (running) {
        try {
            buf.clear();
            SocketAddress src = channel.receive(buf);
            buf.flip();
            if (src != null) {
                log.debug("Received datagram from " + src);
                Message message = new Message(buf);
                if (message.getHeader().getOpcode() == Opcode.QUERY) {
                    // Dispatch
                    workers.execute(new ForwardTask(channel, src, message, workers));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:DeepAQ,项目名称:CerDNS,代码行数:21,代码来源:DNSServer.java

示例3: done

import org.xbill.DNS.Message; //导入依赖的package包/类
static void	doAXFR(Message response) throws IOException {
	System.out.println("; java dig 0.0 <> " + name + " axfr");
	if (response.isSigned()) {
		System.out.print(";; TSIG ");
		if (response.isVerified())
			System.out.println("ok");
		else
			System.out.println("failed");
	}

	if (response.getRcode() != Rcode.NOERROR) {
		System.out.println(response);
		return;
	}

	Record [] records = response.getSectionArray(Section.ANSWER);
	for (int i = 0; i < records.length; i++)
		System.out.println(records[i]);

	System.out.print(";; done (");
	System.out.print(response.getHeader().getCount(Section.ANSWER));
	System.out.print(" records, ");
	System.out.print(response.getHeader().getCount(Section.ADDITIONAL));
	System.out.println(" additional)");
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:26,代码来源:Dig.java

示例4: dnsLookup

import org.xbill.DNS.Message; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:31,代码来源:DNSLookupService.java

示例5: getPortFromResponse

import org.xbill.DNS.Message; //导入依赖的package包/类
public static int getPortFromResponse(Message m) {
	for (int i = 0; i < 4; i++) {
		try { // Can do something with the counts field here, instead of
			// cycling through all of these
			Record[] records = m.getSectionArray(i);
			if (records != null) {
				for (int j = 0; j < records.length; j++) {
					if ((records[j]).getClass().equals(TXTRecord.class)) {
						return Integer.valueOf(
								((String) (((TXTRecord) (records[j]))
										.getStrings().get(0)))).intValue();
					}
				}
			}
		} catch (IndexOutOfBoundsException e) {
			// carry on!
		}
	}
	return -999;
}
 
开发者ID:jyeary,项目名称:dnsjnio,代码行数:21,代码来源:PortTest.java

示例6: testPublishDomainFails_whenDnsUpdateReturnsError

import org.xbill.DNS.Message; //导入依赖的package包/类
@Test
public void testPublishDomainFails_whenDnsUpdateReturnsError() throws Exception {
  DomainResource domain =
      persistActiveDomain("example.tld")
          .asBuilder()
          .setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.tld"))))
          .build();
  persistResource(domain);
  when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL));
  VerifyException thrown =
      expectThrows(
          VerifyException.class,
          () -> {
            writer.publishDomain("example.tld");
            writer.commit();
          });
  assertThat(thrown).hasMessageThat().contains("SERVFAIL");
}
 
开发者ID:google,项目名称:nomulus,代码行数:19,代码来源:DnsUpdateWriterTest.java

示例7: testPublishHostFails_whenDnsUpdateReturnsError

import org.xbill.DNS.Message; //导入依赖的package包/类
@Test
public void testPublishHostFails_whenDnsUpdateReturnsError() throws Exception {
  HostResource host =
      persistActiveSubordinateHost("ns1.example.tld", persistActiveDomain("example.tld"))
          .asBuilder()
          .setInetAddresses(ImmutableSet.of(InetAddresses.forString("10.0.0.1")))
          .build();
  persistResource(host);
  when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL));
  VerifyException thrown =
      expectThrows(
          VerifyException.class,
          () -> {
            writer.publishHost("ns1.example.tld");
            writer.commit();
          });
  assertThat(thrown).hasMessageThat().contains("SERVFAIL");
}
 
开发者ID:google,项目名称:nomulus,代码行数:19,代码来源:DnsUpdateWriterTest.java

示例8: toRecord

import org.xbill.DNS.Message; //导入依赖的package包/类
/**
 * @param ip, like "192.168.1.1"
 * @return the complete DNS record for that IP.
 */
@Converter
public static Record toRecord(String ip) throws IOException {
    Resolver res = new ExtendedResolver();

    Name name = ReverseMap.fromAddress(ip);
    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 null;
    } else {
        return answers[0];
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:DnsRecordConverter.java

示例9: testDigForMonkey

import org.xbill.DNS.Message; //导入依赖的package包/类
@Test
@Ignore("Testing behind nat produces timeouts")
public void testDigForMonkey() throws Exception {
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {
        public boolean matches(Exchange exchange) {
            String str = ((Message) exchange.getIn().getBody()).getSectionArray(Section.ANSWER)[0].rdataToString();
            return RESPONSE_MONKEY.equals(str);
        }
    });
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("dns.name", "monkey.wp.dg.cx");
    headers.put("dns.type", "TXT");
    template.sendBodyAndHeaders(null, headers);
    resultEndpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:DnsDigEndpointSpringTest.java

示例10: dump

import org.xbill.DNS.Message; //导入依赖的package包/类
private static void dump(DatagramPacket packet, boolean send) {
	if (!verbose) {
		return;
	}
	StringWriter sw = new StringWriter();
	PrintWriter out = new PrintWriter(sw);
	out.println((send ? "Sent to " : "Received from ") +
			packet.getAddress().getHostAddress());
	byte[] data = Bytes.sub(packet.getData(), packet.getOffset(), packet.getLength());
	Bytes.dump(out, data);
	try {
		out.println(new Message(data));
	} catch (IOException e) {
		out.println(e.getMessage());
	}
	Log.d(sw.toString());
}
 
开发者ID:xqbase,项目名称:ddns,代码行数:18,代码来源:DDNS.java

示例11: findAddressesRecursive

import org.xbill.DNS.Message; //导入依赖的package包/类
private String[] findAddressesRecursive(Set<Name> stack, Name target) throws IOException {
	String[] ipv4Addresses = null;
	String[] ipv6Addresses = null;
	Message ipv4 = lookup(stack, getRoots(), Message.newQuery(Record.newRecord(target, Type.A, DClass.IN)));
	if (ipv4 != null)
		ipv4Addresses = findAddresses(target, ipv4.getSectionArray(Section.ANSWER));
	Message ipv6 = lookup(stack, getRoots(), Message.newQuery(Record.newRecord(target, Type.AAAA, DClass.IN)));
	if (ipv6 != null)
		ipv6Addresses = findAddresses(target, ipv6.getSectionArray(Section.ANSWER));

	String[] addresses = new String[0];
	if (ipv4Addresses != null)
		addresses = ipv4Addresses;
	if (ipv6Addresses != null) {
		String[] concatAddresses = new String[addresses.length + ipv6Addresses.length];
		System.arraycopy(addresses, 0, concatAddresses, 0, addresses.length);
		System.arraycopy(ipv6Addresses, 0, concatAddresses, addresses.length, ipv6Addresses.length);
		addresses = concatAddresses;
	}

	if (addresses.length == 0)
		return null;
	return addresses;
}
 
开发者ID:wnagele,项目名称:dnsjava-recursive-resolver,代码行数:25,代码来源:RecursiveResolver.java

示例12: getCached

import org.xbill.DNS.Message; //导入依赖的package包/类
private Message getCached(Message query) {
	Cache cache = getCache();
	if (cache == null)
		return null;

	Record question = query.getQuestion();
	RRset[] rrsets = cache.findAnyRecords(question.getName(), question.getType());
	if (rrsets == null)
		return null;

	Message msg = new Message();
	for (RRset rrset : rrsets) {
		@SuppressWarnings("unchecked")
		Iterator<Record> recordsIter = rrset.rrs();
		while (recordsIter.hasNext()) {
			msg.addRecord(recordsIter.next(), Section.ANSWER);
		}
	}
	return msg;
}
 
开发者ID:wnagele,项目名称:dnsjava-recursive-resolver,代码行数:21,代码来源:RecursiveResolver.java

示例13: processDNSKEYResponse

import org.xbill.DNS.Message; //导入依赖的package包/类
private void processDNSKEYResponse(Message request, SMessage response, FindKeyState state) {
    Name qname = request.getQuestion().getName();
    int qclass = request.getQuestion().getDClass();

    SRRset dnskeyRrset = response.findAnswerRRset(qname, Type.DNSKEY, qclass);
    if (dnskeyRrset == null) {
        // If the DNSKEY rrset was missing, this is the end of the line.
        state.keyEntry = KeyEntry.newBadKeyEntry(qname, qclass, DEFAULT_TA_BAD_KEY_TTL);
        state.keyEntry.setBadReason(R.get("dnskey.no_rrset", qname));
        return;
    }

    state.keyEntry = this.valUtils.verifyNewDNSKEYs(dnskeyRrset, state.dsRRset, DEFAULT_TA_BAD_KEY_TTL);

    // If the key entry isBad or isNull, then we can move on to the next
    // state.
    if (!state.keyEntry.isGood()) {
        return;
    }

    // The DNSKEY validated, so cache it as a trusted key rrset.
    this.keyCache.store(state.keyEntry);

    // If good, we stay in the FINDKEY state.
    this.processFindKey(state);
}
 
开发者ID:ibauersachs,项目名称:dnssecjava,代码行数:27,代码来源:ValidatingResolver.java

示例14: testUnsignedThatMustBeSigned

import org.xbill.DNS.Message; //导入依赖的package包/类
@Test
public void testUnsignedThatMustBeSigned() throws IOException {
    Name query = Name.fromString("www.ingotronic.ch.");

    // prepare a faked, unsigned response message that must have a signature
    // to be valid
    Message message = new Message();
    message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION);
    message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER);
    add("www.ingotronic.ch./A", message);

    Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
    assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
    assertEquals(Rcode.SERVFAIL, response.getRcode());
    assertEquals("validate.bogus.missingsig", getReason(response));
}
 
开发者ID:ibauersachs,项目名称:dnssecjava,代码行数:17,代码来源:TestInvalid.java

示例15: testDNameWithNoCnameIsValid

import org.xbill.DNS.Message; //导入依赖的package包/类
@Test
public void testDNameWithNoCnameIsValid() throws IOException {
    Message m = resolver.send(createMessage("www.isc.ingotronic.ch./A"));
    Message message = messageFromString(m.toString().replaceAll("(.*CNAME.*)", "").replaceAll("\n\n", "\n"));
    add("www.isc.ingotronic.ch./A", message);

    Message response = resolver.send(createMessage("www.isc.ingotronic.ch./A"));
    assertTrue("AD flag must be set", response.getHeader().getFlag(Flags.AD));
    assertEquals(Rcode.NOERROR, response.getRcode());
    assertNull(getReason(response));
    Lookup l = new Lookup("www.isc.ingotronic.ch");
    l.setResolver(resolver);
    Record[] results = l.run();
    assertTrue(results != null);
    assertTrue(results.length >= 1);
}
 
开发者ID:ibauersachs,项目名称:dnssecjava,代码行数:17,代码来源:TestDNames.java


注:本文中的org.xbill.DNS.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。