本文整理汇总了Java中org.xbill.DNS.Type.TXT属性的典型用法代码示例。如果您正苦于以下问题:Java Type.TXT属性的具体用法?Java Type.TXT怎么用?Java Type.TXT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.xbill.DNS.Type
的用法示例。
在下文中一共展示了Type.TXT属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getReason
protected String getReason(Message m) {
for (RRset set : m.getSectionRRsets(Section.ADDITIONAL)) {
if (set.getName().equals(Name.root) && set.getType() == Type.TXT && set.getDClass() == ValidatingResolver.VALIDATION_REASON_QCLASS) {
StringBuilder sb = new StringBuilder();
@SuppressWarnings("unchecked")
List<String> strings = (List<String>)((TXTRecord)set.first()).getStrings();
for (String part : strings){
sb.append(part);
}
return sb.toString();
}
}
return null;
}
示例2: getASN
public static Long getASN(final InetAddress adr)
{
try
{
final Name postfix;
if (adr instanceof Inet6Address)
postfix = Name.fromConstantString("origin6.asn.cymru.com");
else
postfix = Name.fromConstantString("origin.asn.cymru.com");
final Name name = getReverseIPName(adr, postfix);
System.out.println("lookup: " + name);
final Lookup lookup = new Lookup(name, Type.TXT);
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 TXTRecord)
{
final TXTRecord txt = (TXTRecord) record;
@SuppressWarnings("unchecked")
final List<String> strings = txt.getStrings();
if (strings != null && !strings.isEmpty())
{
final String result = strings.get(0);
final String[] parts = result.split(" ?\\| ?");
if (parts != null && parts.length >= 1)
return new Long(parts[0].split(" ")[0]);
}
}
}
catch (final Exception e)
{
}
return null;
}
示例3: getASName
public static String getASName(final long asn)
{
try
{
final Name postfix = Name.fromConstantString("asn.cymru.com.");
final Name name = new Name(String.format("AS%d", asn), postfix);
System.out.println("lookup: " + name);
final Lookup lookup = new Lookup(name, Type.TXT);
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 TXTRecord)
{
final TXTRecord txt = (TXTRecord) record;
@SuppressWarnings("unchecked")
final List<String> strings = txt.getStrings();
if (strings != null && !strings.isEmpty())
{
System.out.println(strings);
final String result = strings.get(0);
final String[] parts = result.split(" ?\\| ?");
if (parts != null && parts.length >= 1)
return parts[4];
}
}
}
catch (final Exception e)
{
}
return null;
}
示例4: getAScountry
public static String getAScountry(final long asn)
{
try
{
final Name postfix = Name.fromConstantString("asn.cymru.com.");
final Name name = new Name(String.format("AS%d", asn), postfix);
System.out.println("lookup: " + name);
final Lookup lookup = new Lookup(name, Type.TXT);
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 TXTRecord)
{
final TXTRecord txt = (TXTRecord) record;
@SuppressWarnings("unchecked")
final List<String> strings = txt.getStrings();
if (strings != null && !strings.isEmpty())
{
final String result = strings.get(0);
final String[] parts = result.split(" ?\\| ?");
if (parts != null && parts.length >= 1)
return parts[1];
}
}
}
catch (final Exception e)
{
}
return null;
}
示例5: process
@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);
}
}
示例6: getTXT
public String getTXT(String key) throws ConfigException {
String qkey = fullyQualify(key);
List<Record> list = m_records.get(makeHostKey(qkey));
if (list == null || list.get(0).getType() != Type.TXT) {
throw new NotFoundException("No such record: " + makeHostKey(qkey));
}
TXTRecord trec = (TXTRecord) list.get(0);
String sdata = trec.rdataToString();
if (sdata.charAt(0) == '"') {
sdata = sdata.substring(1, sdata.length() - 1);
}
return sdata;
}
示例7: resolveAPITXT
/**
* Adapted from https://code.google.com/p/asmack/source/browse/src/custom/org/jivesoftware/smack/util/DNSUtil.java
*
* @param domain
* @return
* @throws TextParseException
*/
@SuppressWarnings("unchecked")
private static String resolveAPITXT(String domain) throws TextParseException {
Lookup lookup = new Lookup(TXT_PREFIX + domain, Type.TXT);
Record recs[] = lookup.run();
if (recs == null) {
throw new RuntimeException("Could not lookup domain.");
}
Map<String, String> stringMap = null;
for (Record rec : recs) {
String rData = rec.rdataToString().replaceAll("\"", "");
List<String> rDataTokens = Arrays.asList(rData.split("\\s+"));
TXTRecord record = new TXTRecord(rec.getName(), rec.getDClass(),
rec.getTTL(), rDataTokens);
List<String> strings = record.getStrings();
if (strings != null && strings.size() > 0) {
stringMap = parseStrings(strings);
break;
}
}
if (stringMap == null) {
throw new RuntimeException("Domain has no TXT records for buddycloud.");
}
String host = stringMap.get("host");
String protocol = stringMap.get("protocol");
String path = stringMap.get("path");
String port = stringMap.get("port");
path = path == null || path.equals("/") ? "" : path;
port = port == null ? "" : port;
return protocol + "://" + host + ":" + port + path;
}
示例8: 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);
}
}
示例9: checkDnsSec
/**
* 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;
}
示例10: getTXTRecords
public List<String>
getTXTRecords(
String query )
{
List<String> result = new ArrayList<>(2);
try{
Lookup l = new Lookup( query, Type.TXT );
setCache( null, l );
l.run();
Record[] records = l.getAnswers();
if ( records != null ){
for ( Record r: records ){
TXTRecord txt = (TXTRecord)r;
result.addAll((List<String>)txt.getStrings());
}
}
}catch( Throwable e ){
}
return( result );
}
示例11: getTXTRecord
public String
getTXTRecord(
String query )
throws UnknownHostException
{
try{
Lookup l = new Lookup( query, Type.TXT );
setCache( null, l );
l.run();
Record[] records = l.getAnswers();
if ( records != null ){
for ( Record r: records ){
TXTRecord txt = (TXTRecord)r;
List<String> strs = (List<String>)txt.getStrings();
if ( strs.size() > 0 ){
return( strs.get( 0 ));
}
}
}
return( null );
}catch( Throwable e ){
throw( new UnknownHostException( query + ": " + Debug.getNestedExceptionMessage( e )));
}
}