本文整理匯總了Java中org.xbill.DNS.Type.A屬性的典型用法代碼示例。如果您正苦於以下問題:Java Type.A屬性的具體用法?Java Type.A怎麽用?Java Type.A使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.xbill.DNS.Type
的用法示例。
在下文中一共展示了Type.A屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolve
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;
}
示例2: resolve
private List<InetAddress> resolve(String key) throws UnknownHostException {
List<InetAddress> result = new ArrayList<InetAddress>();
List<Record> list = m_records.get(key);
if (list != null)
for (Record r : list)
if (r.getType() == Type.A)
result.add(InetAddress.getByName(r.rdataToString()));
else if ((r.getType() == Type.CNAME)) {
List<Record> cnamelist = m_records.get(r.rdataToString());
for (Record r1 : cnamelist) {
result.add(InetAddress.getByName(r1.rdataToString()));
}
}
return result;
}
示例3: findAddresses
private String[] findAddresses(Name target, Record[] records) {
ArrayList<String> addresses = new ArrayList<String>();
for (Record record : records) {
if (target == null || target.equals(record.getName())) {
int recordType = record.getType();
if (Type.A == recordType)
addresses.add(((ARecord)record).getAddress().getHostAddress());
else if (Type.AAAA == recordType)
addresses.add(((AAAARecord)record).getAddress().getHostAddress());
}
}
if (addresses.size() == 0)
return null;
return addresses.toArray(new String[addresses.size()]);
}
示例4: requestLookup
/**
* Sends DNS request via system or custom DNS resolver
*/
private InetAddress[] requestLookup(String host) throws UnknownHostException {
InetAddress[] addresses = null;
if (isCustomResolver() && ((ExtendedResolver) resolver).getResolvers().length > 0) {
try {
Lookup lookup = new Lookup(host, Type.A);
lookup.setCache(lookupCache);
if (timeoutMs > 0) {
resolver.setTimeout(timeoutMs / 1000, timeoutMs % 1000);
}
lookup.setResolver(resolver);
Record[] records = lookup.run();
if (records == null || records.length == 0) {
throw new UnknownHostException("Failed to resolve host name: " + host);
}
addresses = new InetAddress[records.length];
for (int i = 0; i < records.length; i++) {
addresses[i] = ((ARecord) records[i]).getAddress();
}
} catch (TextParseException tpe) {
log.debug("Failed to create Lookup object: " + tpe);
}
} else {
addresses = systemDefaultDnsResolver.resolve(host);
if (log.isDebugEnabled()) {
log.debug("Cache miss: " + host + " Thread #" + JMeterContextService.getContext().getThreadNum()
+ ", resolved with system resolver into " + Arrays.toString(addresses));
}
}
return addresses;
}
示例5: process
@Override
public void process(Exchange exchange) throws Exception {
String server = exchange.getIn().getHeader(DnsConstants.DNS_SERVER, String.class);
SimpleResolver resolver = new SimpleResolver(server);
int type = Type.value(exchange.getIn().getHeader(DnsConstants.DNS_TYPE, String.class));
if (type == -1) {
// default: if unparsable value given, use A.
type = Type.A;
}
String dclassValue = exchange.getIn().getHeader(DnsConstants.DNS_CLASS, String.class);
if (dclassValue == null) {
dclassValue = "";
}
int dclass = DClass.value(dclassValue);
if (dclass == -1) {
// by default, value is IN.
dclass = DClass.IN;
}
Name name = Name.fromString(exchange.getIn().getHeader(DnsConstants.DNS_NAME, String.class), Name.root);
Record rec = Record.newRecord(name, type, dclass);
Message query = Message.newQuery(rec);
Message response = resolver.send(query);
exchange.getIn().setBody(response);
}
示例6: firstA
@SuppressWarnings("unchecked")
protected String firstA(Message response) {
RRset[] sectionRRsets = response.getSectionRRsets(Section.ANSWER);
if (sectionRRsets.length > 0) {
Iterator<Record> rrs = sectionRRsets[0].rrs();
while (rrs.hasNext()) {
Record r = rrs.next();
if (r.getType() == Type.A) {
return ((ARecord)r).getAddress().getHostAddress();
}
}
}
return null;
}
示例7: process
/**
* Processes a DNS query.
*
* @param sock
* Socket to listen to
*/
private void process(DatagramSocket sock) {
try {
byte[] in = new byte[UDP_SIZE];
// Read the question
DatagramPacket indp = new DatagramPacket(in, UDP_SIZE);
indp.setLength(UDP_SIZE);
sock.receive(indp);
Message msg = new Message(in);
Header header = msg.getHeader();
Record question = msg.getQuestion();
// Prepare a response
Message response = new Message(header.getID());
response.getHeader().setFlag(Flags.QR);
response.addRecord(question, Section.QUESTION);
Name name = question.getName();
boolean hasRecords = false;
String txt = txtRecords.get(name.toString(true));
if (question.getType() == Type.TXT && txt != null) {
response.addRecord(new TXTRecord(name, DClass.IN, TTL, txt), Section.ANSWER);
hasRecords = true;
LOG.info("dns-01: {} {} IN TXT \"{}\"", name, TTL, txt);
}
InetAddress a = aRecords.get(name.toString(true));
if (question.getType() == Type.A && a != null) {
response.addRecord(new ARecord(name, DClass.IN, TTL, a), Section.ANSWER);
hasRecords = true;
LOG.info("dns-01: {} {} IN A {}", name, TTL, a.getHostAddress());
}
if (!hasRecords) {
response.getHeader().setRcode(Rcode.NXDOMAIN);
LOG.warn("dns-01: Cannot answer: {}", question);
}
// Send the response
byte[] resp = response.toWire();
DatagramPacket outdp = new DatagramPacket(resp, resp.length, indp.getAddress(), indp.getPort());
sock.send(outdp);
} catch (Exception ex) {
LOG.error("Failed to process query", ex);
}
}
示例8: testAtLeastOneSupportedAlgorithmWithOnlyNonDSRecords
@Test
public void testAtLeastOneSupportedAlgorithmWithOnlyNonDSRecords() {
RRset set = new RRset(new NSECRecord(Name.root, DClass.IN, 0, Name.root, new int[] { Type.A }));
boolean result = ValUtils.atLeastOneSupportedAlgorithm(set);
assertFalse(result);
}
示例9: testAtLeastOneDigestSupportedWithOnlyNonDSRecords
@Test
public void testAtLeastOneDigestSupportedWithOnlyNonDSRecords() {
RRset set = new RRset(new NSECRecord(Name.root, DClass.IN, 0, Name.root, new int[] { Type.A }));
boolean result = ValUtils.atLeastOneDigestSupported(set);
assertFalse(result);
}
示例10: main
public static void main(String[] args) {
// System.err.println("Outcome: "
// + CheckEmailObj.checkEmail("[email protected]"));
String qqhostName = "qq.com";
String qqhostName2 = "outlook.com";
System.out.println(DNSResolver.checkDNS(qqhostName2, false));
// System.out.println(DNSResolver.checkDNS("outlook.com", true));
try {
Lookup lookup = new Lookup(qqhostName2, Type.A);
lookup.run();
for(Record r : lookup.getAnswers())
System.out.println(r);
} catch (TextParseException e) {
e.printStackTrace();
}
// System.out.println( MailChecker.validate("[email protected]"));
}