本文整理汇总了Java中org.xbill.DNS.Record.newRecord方法的典型用法代码示例。如果您正苦于以下问题:Java Record.newRecord方法的具体用法?Java Record.newRecord怎么用?Java Record.newRecord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xbill.DNS.Record
的用法示例。
在下文中一共展示了Record.newRecord方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dnsLookup
import org.xbill.DNS.Record; //导入方法依赖的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;
}
示例2: toRecord
import org.xbill.DNS.Record; //导入方法依赖的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];
}
}
示例3: reverseDnsLookupUsingDnsJavaSimpleResolver
import org.xbill.DNS.Record; //导入方法依赖的package包/类
private static String reverseDnsLookupUsingDnsJavaSimpleResolver(long ipAddress) throws IOException {
String result = null;
byte[] address = convertLongAddressToBuf(ipAddress);
Name name = ReverseMap.fromAddress(InetAddress.getByAddress(address));
Record record = Record.newRecord(name, Type.PTR, DClass.IN);
Message query = Message.newQuery(record);
Message response = simpleResolver.send(query);
Record[] answers = response.getSectionArray(Section.ANSWER);
if (answers.length != 0) {
// If PTR-record exists this will be at index 1 or above (more than one PTR-record may exist)
Record answer = (answers.length > 1) ? answers[1] : answers[0];
result = answer.rdataToString();
// remove trailing "."
result = result.endsWith(".") ? result.substring(0, result.length() - 1) : result;
} else {
throw new IOException("Empty DNS response.");
}
return result;
}
示例4: makeQuery
import org.xbill.DNS.Record; //导入方法依赖的package包/类
public static synchronized Message makeQuery(String nameString, int id) throws TextParseException {
Name name = Name.fromString(nameString, Name.root);
Record question = Record.newRecord(name, Type.A, DClass.ANY);
Message query = Message.newQuery(question);
query.getHeader().setID(id);
return query;
}
示例5: process
import org.xbill.DNS.Record; //导入方法依赖的package包/类
@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: process
import org.xbill.DNS.Record; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
SimpleResolver resolver = new SimpleResolver();
int type = Type.TXT;
Name name = Name.fromString(String.valueOf(exchange.getIn().getHeader(DnsConstants.TERM)) + ".wp.dg.cx", Name.root);
Record rec = Record.newRecord(name, type, DClass.IN);
Message query = Message.newQuery(rec);
Message response = resolver.send(query);
Record[] records = response.getSectionArray(Section.ANSWER);
if (records.length > 0) {
exchange.getIn().setBody(records[0].rdataToString());
} else {
exchange.getIn().setBody(null);
}
}
示例7: messageWithRCode
import org.xbill.DNS.Record; //导入方法依赖的package包/类
private Message messageWithRCode(String query, int rcode) throws TextParseException {
Name queryName = Name.fromString(query);
Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
Message queryMessage = Message.newQuery(question);
Message result = new Message();
result.setHeader(queryMessage.getHeader());
result.addRecord(question, Section.QUESTION);
result.getHeader().setRcode(rcode);
return result;
}
示例8: messageWithNodes
import org.xbill.DNS.Record; //导入方法依赖的package包/类
private Message messageWithNodes(String query, Iterable<String> names) throws TextParseException {
Name queryName = Name.fromString(query);
Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
Message queryMessage = Message.newQuery(question);
Message result = new Message();
result.setHeader(queryMessage.getHeader());
result.addRecord(question, Section.QUESTION);
for (String name1 : names){
result.addRecord(new SRVRecord(queryName, DClass.IN, 1, 1, 1, 8080, Name.fromString(name1)), Section.ANSWER);
}
return result;
}
示例9: parseQuestion
import org.xbill.DNS.Record; //导入方法依赖的package包/类
private Record parseQuestion(String line) throws TextParseException {
String[] temp = line.replaceAll("\\s+", " ").split(" ");
if (Type.value(temp[2]) == -1) {
System.out.println(temp[2]);
}
return Record.newRecord(Name.fromString(temp[0]), Type.value(temp[2]), DClass.value(temp[1]));
}
示例10: getQuery
import org.xbill.DNS.Record; //导入方法依赖的package包/类
private Message getQuery(String nameString) throws TextParseException {
Name name = Name.fromString(nameString, Name.root);
Record question = Record.newRecord(name, Type.A, DClass.ANY);
return Message.newQuery(question);
}
示例11: checkDnsSec
import org.xbill.DNS.Record; //导入方法依赖的package包/类
/**
* Validate the DNSSEC trust chain against the provided domain name (i.e. <code>Fqdn</code>).
*
* @param name A <code>Fqdn</code> representing the validating domain
* @param resolver A DNS <code>Resovler</code> to be used in this validation
* @param rType An integer representing the record type
*
* @return <code>true</code> iff the DNSSEC is valid
*
* @throws LookupException
* Containing the specific <code>StatusCode</code> defining the error that has been raised.
*/
public static boolean checkDnsSec(Fqdn name, Resolver resolver, int rType)
throws LookupException
{
try {
ValidatingResolver validating = (ValidatingResolver) resolver;
Record toValidate = Record.newRecord(Name.fromConstantString(name.fqdn()), rType, DClass.IN);
Message dnsResponse = validating.send(Message.newQuery(toValidate));
RRset[] rrSets = dnsResponse.getSectionRRsets(Section.ADDITIONAL);
StringBuilder reason = new StringBuilder("");
for (RRset rrset : rrSets) {
if (rrset.getName().equals(Name.root) && rrset.getType() == Type.TXT
&& rrset.getDClass() == ValidatingResolver.VALIDATION_REASON_QCLASS) {
reason.append(TextRecord.build((TXTRecord) rrset.first()).getRData());
}
}
StatusCode outcome = StatusCode.SUCCESSFUL_OPERATION;
if (dnsResponse.getRcode() == Rcode.SERVFAIL) {
if (reason.toString().toLowerCase().contains(CHAIN_OF_TRUST)
|| reason.toString().toLowerCase().contains(INSECURE)) {
outcome = StatusCode.RESOURCE_INSECURE_ERROR;
} else if (reason.toString().toLowerCase().contains(NO_DATA)) {
outcome = StatusCode.NETWORK_ERROR;
} else if (reason.toString().toLowerCase().contains(NO_SIGNATURE)
|| reason.toString().toLowerCase().contains(MISSING_KEY)) {
outcome = StatusCode.RESOLUTION_NAME_ERROR;
}
} else if (dnsResponse.getRcode() == Rcode.NXDOMAIN) {
if (reason.toString().toLowerCase().contains(NSEC3_NO_DS)) {
outcome = StatusCode.RESOURCE_INSECURE_ERROR;
} else {
outcome = StatusCode.RESOLUTION_NAME_ERROR;
}
} else if (dnsResponse.getRcode() == Rcode.NOERROR
&& !dnsResponse.getHeader().getFlag(Flags.AD)) {
outcome = StatusCode.RESOURCE_INSECURE_ERROR;
}
if (outcome != StatusCode.SUCCESSFUL_OPERATION) {
throw ExceptionsUtil.build(outcome,
"DNSSEC Validation Failed",
new LinkedHashMap<String, StatusCode>());
}
} catch (IOException e) {
// it might be a transient error network: retry with next Resolver
return false;
}
return true;
}