當前位置: 首頁>>代碼示例>>Java>>正文


Java Name類代碼示例

本文整理匯總了Java中org.xbill.DNS.Name的典型用法代碼示例。如果您正苦於以下問題:Java Name類的具體用法?Java Name怎麽用?Java Name使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Name類屬於org.xbill.DNS包,在下文中一共展示了Name類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.xbill.DNS.Name; //導入依賴的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: reverseDNSLookup

import org.xbill.DNS.Name; //導入依賴的package包/類
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;
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:24,代碼來源:Helperfunctions.java

示例3: dnsLookup

import org.xbill.DNS.Name; //導入依賴的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

示例4: testSentMessageTooLongThrowsException

import org.xbill.DNS.Name; //導入依賴的package包/類
@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 =
      expectThrows(IllegalArgumentException.class, () -> resolver.send(oversize));
  assertThat(thrown).hasMessageThat().contains("message larger than maximum");
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:17,代碼來源:DnsMessageTransportTest.java

示例5: toRecord

import org.xbill.DNS.Name; //導入依賴的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

示例6: buildRecord

import org.xbill.DNS.Name; //導入依賴的package包/類
/** Builds a CERT record from a Certificate associated with a key also in DNS */
public static CERTRecord
buildRecord(Name name, int dclass, long ttl, Certificate cert, int tag,
	    int alg)
{
	int type;
	byte [] data;

	try {
		if (cert instanceof X509Certificate) {
			type = CERTRecord.PKIX;
			data = cert.getEncoded();
		}
		else
			return null;

		return new CERTRecord(name, dclass, ttl, type, tag, alg, data);
	}
	catch (CertificateException e) {
		if (Options.check("verboseexceptions"))
			System.err.println("Cert build exception:" + e);
		return null;
	}
}
 
開發者ID:epam,項目名稱:Wilma,代碼行數:25,代碼來源:CERTConverter.java

示例7: resolveHostByName

import org.xbill.DNS.Name; //導入依賴的package包/類
private String resolveHostByName(Resolver resolver, Name target) {
    Lookup lookup = new Lookup(target, A);
    if (resolver != null) {
        lookup.setResolver(resolver);
    }
    Record[] records = lookup.run();
    Optional<InetAddress> address = of(records)
            .filter(it -> it instanceof ARecord)
            .map(a -> ((ARecord) a).getAddress())
            .findFirst();
    if (address.isPresent()) {
        return address.get().getHostAddress();
    } else {
        log.warn("unknown name: " + target);
        return null;
    }
}
 
開發者ID:amirkibbar,項目名稱:plum,代碼行數:18,代碼來源:DnsResolver.java

示例8: queryMxTargets

import org.xbill.DNS.Name; //導入依賴的package包/類
/**
 * Returns an ordered host name list based on the MX records of the domain.
 * The first has the highest priority. If the domain has no MX records, then
 * it returns the host itself. Records with the same priority are shuffled
 * randomly.
 * 
 * @see <a href="http://tools.ietf.org/html/rfc5321#section-5.1">RFC 5321
 *      Simple Mail Transfer Protocol - Locating the Target Host</a>
 */
public Name[] queryMxTargets(Domain domain) throws MxLookupException {
    MXRecord[] records = queryMxRecords(domain);
    if (records.length == 0) {
        logger.debug("Domain {} has no MX records, using an implicit "
                + "MX record targetting the host", domain);
        return implicitMxTargetForDomain(domain);
    } else {
        //
        ArrayList<MXRecord> list =
                new ArrayList<MXRecord>(Arrays.asList(records));
        Collections.shuffle(list);
        // This sort is guaranteed to be stable: equal elements will not be
        // reordered as a result of the sort, so shuffle remains in effect
        Collections.sort(list, mxRecordPriorityComparator);
        list.toArray(records);
        return convertMxRecordsToHostNames(records);
    }
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:28,代碼來源:MxLookup.java

示例9: testSendToAddressLiteralVerifyNoDns

import org.xbill.DNS.Name; //導入依賴的package包/類
@Test
public void testSendToAddressLiteralVerifyNoDns() throws SendException,
        RecipientsWereRejectedException, PostponeException {

    sender.send(adaAddressLiteralMail);
    
    new Verifications() {
        {
            mxLookup.queryMxTargets((Domain)any);
            times = 0;

            addressLookup.queryAddresses((Name)any);
            times = 0;

            mailToHostTransmitter.transmit((Mail) any, null);
            
            client.setMtaAddress(new MtaAddress(ADDRESS_LITERAL, IP));
        }
    };
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:21,代碼來源:DirectImmediateSenderTest.java

示例10: testSendToDomain

import org.xbill.DNS.Name; //導入依賴的package包/類
@Test
public void testSendToDomain() throws SendException,
        RecipientsWereRejectedException, PostponeException {
    new Expectations() {
        {
            mxLookup.queryMxTargets((Domain)any);
            result = new Name[] { HOST1_EXAMPLE_COM_NAME };

            addressLookup.queryAddresses((Name)any);
            result = new InetAddress[] { IP_ADDRESS_ONLY };

            client.setMtaAddress(new MtaAddress("host1.example.com", IP));
            
            mailToHostTransmitter.transmit((Mail) any, null);
        }
    };

    sender.send(mail);
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:20,代碼來源:DirectImmediateSenderTest.java

示例11: testSendFirstMxCannotBeResolved

import org.xbill.DNS.Name; //導入依賴的package包/類
@Test
public void testSendFirstMxCannotBeResolved() throws SendException,
        RecipientsWereRejectedException, PostponeException {
    new Expectations() {
        {
            mxLookup.queryMxTargets((Domain)any);
            result =
                    new Name[] { HOST1_EXAMPLE_COM_NAME,
                            HOST2_EXAMPLE_COM_NAME };

            addressLookup.queryAddresses((Name)any);
            result = permanentSendException;
            result = new InetAddress[] { IP2 };

            client.setMtaAddress(new MtaAddress("host2.example.com", IP2));
            
            mailToHostTransmitter.transmit((Mail) any, null);
        }
    };

    sender.send(mail);
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:23,代碼來源:DirectImmediateSenderTest.java

示例12: twoMxDnsExpectation

import org.xbill.DNS.Name; //導入依賴的package包/類
private void twoMxDnsExpectation() throws SendException {
    new NonStrictExpectations() {
        {
            mxLookup.queryMxTargets((Domain)any);
            result =
                    new Name[] { HOST1_EXAMPLE_COM_NAME,
                            HOST2_EXAMPLE_COM_NAME };
            times = 1;

            addressLookup.queryAddresses((Name)any);
            result = new InetAddress[] { IP1 };
            result = new InetAddress[] { IP2 };
            times = 2;
        }
    };
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:17,代碼來源:DirectImmediateSenderTest.java

示例13: testSendFirstHostHasPermanentProblem

import org.xbill.DNS.Name; //導入依賴的package包/類
@Test(expected = SendException.class)
public void testSendFirstHostHasPermanentProblem() throws SendException,
        RecipientsWereRejectedException, PostponeException {
    new Expectations() {
        {
            mxLookup.queryMxTargets((Domain)any);
            result =
                    new Name[] { HOST1_EXAMPLE_COM_NAME,
                            HOST2_EXAMPLE_COM_NAME };

            addressLookup.queryAddresses((Name)any);
            result = new InetAddress[] { IP1 };

            mailToHostTransmitter.transmit((Mail) any, null);
            result = permanentSendException;
        }
    };

    sender.send(mail);
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:21,代碼來源:DirectImmediateSenderTest.java

示例14: testSendSingleHostPermanentlyCannotBeResolved

import org.xbill.DNS.Name; //導入依賴的package包/類
@Test
public void testSendSingleHostPermanentlyCannotBeResolved()
        throws SendException, RecipientsWereRejectedException,
        PostponeException {
    new Expectations() {
        {
            mxLookup.queryMxTargets((Domain)any);
            result = new Name[] { HOST1_EXAMPLE_COM_NAME };

            addressLookup.queryAddresses((Name)any);
            result = permanentSendException;
        }
    };

    try {
        sender.send(mail);
        fail("An exception must have been thrown");
    } catch (SendException e) {
        assertFalse(e.errorStatus().shouldRetry());
    }
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:22,代碼來源:DirectImmediateSenderTest.java

示例15: testSendSingleHostTemporarilyCannotBeResolved

import org.xbill.DNS.Name; //導入依賴的package包/類
@Test
public void testSendSingleHostTemporarilyCannotBeResolved()
        throws SendException, RecipientsWereRejectedException,
        PostponeException {
    new Expectations() {
        {
            mxLookup.queryMxTargets((Domain)any);
            result = new Name[] { HOST1_EXAMPLE_COM_NAME };

            addressLookup.queryAddresses((Name)any);
            result = transientSendException;
        }
    };

    try {
        sender.send(mail);
        fail("An exception must have been thrown");
    } catch (SendException e) {
        assertTrue(e.errorStatus().shouldRetry());
    }
}
 
開發者ID:hontvari,項目名稱:mireka,代碼行數:22,代碼來源:DirectImmediateSenderTest.java


注:本文中的org.xbill.DNS.Name類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。