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


Java Type类代码示例

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


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

示例1: resolve

import org.xbill.DNS.Type; //导入依赖的package包/类
/**
 * Attempts to resolve an SMTP server address, given the destination e-mail address.
 *
 * @param email The e-mail address used for the lookup.
 * @return An optional, potentially containing
 */
protected Optional<String> resolve(String email) {
    Optional<String> domainOptional = extractDomain(email);

    if (!domainOptional.isPresent()) {
        return Optional.empty();
    }

    String mailDomain = domainOptional.get();

    try {
        Lookup dnsLookup = new Lookup(mailDomain, Type.MX);
        List<Record> records = Arrays.asList(dnsLookup.run());

        if (records.isEmpty()) {
            return Optional.empty();
        }

        return chooseBestRecord(records);

    } catch (TextParseException e) {
        e.printStackTrace();
    }

    return Optional.empty();
}
 
开发者ID:stevesoltys,项目名称:carrier,代码行数:32,代码来源:MailResolverService.java

示例2: resolve

import org.xbill.DNS.Type; //导入依赖的package包/类
public static String resolve(String host, int addrType) {
    try {
        Lookup lookup = new Lookup(host, addrType);
        SimpleResolver resolver = new SimpleResolver("114.114.114.114");
        resolver.setTimeout(5);
        lookup.setResolver(resolver);
        Record[] result = lookup.run();
        if (result == null) return null;

        List<Record> records = java.util.Arrays.asList(result);
        java.util.Collections.shuffle(records);
        for (Record record : records) {
            if (addrType == Type.A) {
                return ((ARecord) record).getAddress().getHostAddress();
            } else if (addrType == Type.AAAA) {
                return ((AAAARecord) record).getAddress().getHostAddress();
            }
        }

    } catch (Exception ex) {
        return null;
    }

    return null;
}
 
开发者ID:lparam,项目名称:xTun-android,代码行数:26,代码来源:Utils.java

示例3: main

import org.xbill.DNS.Type; //导入依赖的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

示例4: testDnsJavaWithDnsServer

import org.xbill.DNS.Type; //导入依赖的package包/类
@Test
public void testDnsJavaWithDnsServer() throws TextParseException, UnknownHostException {
    final Lookup l = new Lookup("example.com", Type.AAAA);
    final SimpleResolver resolver = new SimpleResolver("::1");
    resolver.setPort(9153);
    l.setResolver(resolver);
    l.run();
    
    System.out.println("result: " + l.getResult());
    final Record[] answers = l.getAnswers();
    assertEquals(answers.length, 1);
    
    final Record record = answers[0];
    System.err.println(record.getTTL());
    
    if(l.getResult() == Lookup.SUCCESSFUL) {
        System.out.println(l.getAnswers()[0].rdataToString());
    }
    assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:21,代码来源:DnsMonitorTest.java

示例5: reverseDNSLookup

import org.xbill.DNS.Type; //导入依赖的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

示例6: dnsLookup

import org.xbill.DNS.Type; //导入依赖的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

示例7: resolveRemapped

import org.xbill.DNS.Type; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:21,代码来源:DnsJavaResolver.java

示例8: testPublishDomainCreate_publishesNameServers

import org.xbill.DNS.Type; //导入依赖的package包/类
@Test
public void testPublishDomainCreate_publishesNameServers() throws Exception {
  HostResource host1 = persistActiveHost("ns1.example.tld");
  HostResource host2 = persistActiveHost("ns2.example.tld");
  DomainResource domain =
      persistActiveDomain("example.tld")
          .asBuilder()
          .setNameservers(ImmutableSet.of(Key.create(host1), Key.create(host2)))
          .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
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:DnsUpdateWriterTest.java

示例9: testPublishAtomic_oneUpdate

import org.xbill.DNS.Type; //导入依赖的package包/类
@Test
public void testPublishAtomic_oneUpdate() throws Exception {
  HostResource host1 = persistActiveHost("ns.example1.tld");
  DomainResource domain1 =
      persistActiveDomain("example1.tld")
          .asBuilder()
          .setNameservers(ImmutableSet.of(Key.create(host1)))
          .build();
  persistResource(domain1);

  HostResource host2 = persistActiveHost("ns.example2.tld");
  DomainResource domain2 =
      persistActiveDomain("example2.tld")
          .asBuilder()
          .setNameservers(ImmutableSet.of(Key.create(host2)))
          .build();
  persistResource(domain2);

  writer.publishDomain("example1.tld");
  writer.publishDomain("example2.tld");
  writer.commit();

  verify(mockResolver).send(updateCaptor.capture());
  Update update = updateCaptor.getValue();
  assertThatUpdatedZoneIs(update, "tld.");
  assertThatUpdateDeletes(update, "example1.tld.", Type.ANY);
  assertThatUpdateDeletes(update, "example2.tld.", Type.ANY);
  assertThatUpdateAdds(update, "example1.tld.", Type.NS, "ns.example1.tld.");
  assertThatUpdateAdds(update, "example2.tld.", Type.NS, "ns.example2.tld.");
  assertThatTotalUpdateSetsIs(update, 4); // The delete and NS sets for each TLD
}
 
开发者ID:google,项目名称:nomulus,代码行数:32,代码来源:DnsUpdateWriterTest.java

示例10: testPublishDomainCreate_publishesDelegationSigner

import org.xbill.DNS.Type; //导入依赖的package包/类
@Test
public void testPublishDomainCreate_publishesDelegationSigner() throws Exception {
  DomainResource domain =
      persistActiveDomain("example.tld")
          .asBuilder()
          .setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.tld"))))
          .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
}
 
开发者ID:google,项目名称:nomulus,代码行数:24,代码来源:DnsUpdateWriterTest.java

示例11: testPublishDomainWhenNotActive_removesDnsRecords

import org.xbill.DNS.Type; //导入依赖的package包/类
@Test
public void testPublishDomainWhenNotActive_removesDnsRecords() throws Exception {
  DomainResource domain =
      persistActiveDomain("example.tld")
          .asBuilder()
          .addStatusValue(StatusValue.SERVER_HOLD)
          .setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.tld"))))
          .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
}
 
开发者ID:google,项目名称:nomulus,代码行数:20,代码来源:DnsUpdateWriterTest.java

示例12: testPublishHostDelete_removesGlueRecords

import org.xbill.DNS.Type; //导入依赖的package包/类
@Test
public void testPublishHostDelete_removesGlueRecords() throws Exception {
  persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
  persistResource(
      persistActiveDomain("example.tld")
          .asBuilder()
          .setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.com"))))
          .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);
}
 
开发者ID:google,项目名称:nomulus,代码行数:21,代码来源:DnsUpdateWriterTest.java

示例13: testSentMessageTooLongThrowsException

import org.xbill.DNS.Type; //导入依赖的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

示例14: lookupSRVRecords

import org.xbill.DNS.Type; //导入依赖的package包/类
@Override
public List<SRVRecord> lookupSRVRecords(String name) throws TextParseException {
    List<SRVRecord> res = new ArrayList<SRVRecord>();

    Lookup lookup = new Lookup(name, Type.SRV);
    Record[] recs = lookup.run();
    if (recs == null)
        return res;

    for (Record record : recs) {
        org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record;
        if (srvRecord != null && srvRecord.getTarget() != null) {
            String host = srvRecord.getTarget().toString();
            int port = srvRecord.getPort();
            int priority = srvRecord.getPriority();
            int weight = srvRecord.getWeight();

            SRVRecord r = new SRVRecord(host, port, priority, weight);
            res.add(r);
        }
    }

    return res;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:DNSJavaResolver.java

示例15: toRecord

import org.xbill.DNS.Type; //导入依赖的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


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