本文整理匯總了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();
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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);
}
示例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");
}
示例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;
}
示例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];
}
}