本文整理汇总了Java中org.xbill.DNS.TXTRecord类的典型用法代码示例。如果您正苦于以下问题:Java TXTRecord类的具体用法?Java TXTRecord怎么用?Java TXTRecord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TXTRecord类属于org.xbill.DNS包,在下文中一共展示了TXTRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPortFromResponse
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
public static int getPortFromResponse(Message m) {
for (int i = 0; i < 4; i++) {
try { // Can do something with the counts field here, instead of
// cycling through all of these
Record[] records = m.getSectionArray(i);
if (records != null) {
for (int j = 0; j < records.length; j++) {
if ((records[j]).getClass().equals(TXTRecord.class)) {
return Integer.valueOf(
((String) (((TXTRecord) (records[j]))
.getStrings().get(0)))).intValue();
}
}
}
} catch (IndexOutOfBoundsException e) {
// carry on!
}
}
return -999;
}
示例2: concatenateTxtRecordValues
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
private String concatenateTxtRecordValues(Record[] records) {
if (records == null || records.length == 0)
return null;
StringBuilder builder = new StringBuilder();
for (Record record : records) {
TXTRecord txtRecord = (TXTRecord) record;
if (builder.length() != 0)
builder.append(EOL);
for (Object string : txtRecord.getStrings()) {
if (builder.length() != 0)
builder.append(EOL);
builder.append(string);
}
}
return builder.toString();
}
示例3: getReason
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
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;
}
示例4: getASN
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
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;
}
示例5: getASName
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
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;
}
示例6: getAScountry
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
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;
}
示例7: resolveTextByName
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
/**
* resolves the TXT field for a given name using a specified DNS host and port. This is useful, for example,
* if you want to resolve abusers with: <a href="https://abusix.com/contactdb.html">https://abusix.com/contactdb.html</a>
*
* @param resolverHost name server hostname or IP address
* @param resolverPort name server port
* @param name the DNS name of the TXT record - the name to resolve
* @return the resolved text
*/
public String resolveTextByName(String resolverHost, int resolverPort, String name) {
try {
SimpleResolver resolver = new SimpleResolver(resolverHost);
resolver.setPort(resolverPort);
Lookup lookup = new Lookup(name, TXT);
Record[] records = lookup.run();
if (records != null) {
List<String> addresses =
of(records)
.filter(it -> it instanceof TXTRecord)
.map(it -> collectionToCommaDelimitedString(((TXTRecord) it).getStrings()))
.collect(toList());
return collectionToCommaDelimitedString(addresses);
} else {
return "";
}
} catch (UnknownHostException | TextParseException e) {
log.warn("unable to resolve using TXT record " + name, e);
return "";
}
}
示例8: getTXT
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
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;
}
示例9: parseRecords
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
/**
* Scrapes the Discovery Service Records according to their nature.
*
* @param records An array of <code>Record</code> retrieve upon a lookup
* @param set A <code>ResourcesContainer</code>
* @param pht A Resource Record Type holder
*/
private void parseRecords(Record[] records, final RecordsContainer set, RrHolderType pht)
{
if (records != null) {
for (Record record : records) {
if ((record instanceof PTRRecord && pht == RrHolderType.ZONES) ||
(record instanceof PTRRecord && pht == RrHolderType.NAMES)) {
String zone = PointerRecord.build((PTRRecord) record).getRData();
if (zone != null) {
set.getLabels().add(zone);
}
} else if (record instanceof PTRRecord && pht == RrHolderType.TYPES) {
set.getLabels().add(PointerRecord.build((PTRRecord) record).getServiceType());
} else if (record instanceof SRVRecord) {
ServiceRecord svcRecord = ServiceRecord.build((SRVRecord) record);
if (svcRecord != null) {
set.getRecords().add(svcRecord);
}
} else if (record instanceof TXTRecord) {
set.getTexts().add(TextRecord.build((TXTRecord) record));
} else {
errorsTrace.get().put(
ExceptionsUtil.traceKey(record.toString(), "",
"Parsing-Service-Records"),
StatusCode.RESOURCE_UNEXPECTED);
}
}
}
}
示例10: findTXTRecords
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
/**
* @see org.apache.james.dnsservice.api.DNSService#findTXTRecords(String)
*/
public Collection<String> findTXTRecords(String hostname) {
List<String> txtR = new ArrayList<String>();
Record[] records = lookupNoException(hostname, Type.TXT, "TXT");
if (records != null) {
for (int i = 0; i < records.length; i++) {
TXTRecord txt = (TXTRecord) records[i];
txtR.add(txt.rdataToString());
}
}
return txtR;
}
示例11: resolveAPITXT
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
/**
* 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;
}
示例12: process
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
/**
* 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);
}
}
示例13: checkDnsSec
import org.xbill.DNS.TXTRecord; //导入依赖的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;
}
示例14: createTxtRecord
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
public static TXTRecord createTxtRecord ( String rdata, long ttl ) throws TextParseException {
return new TXTRecord( Name.fromString( "example.com." ), DClass.IN, ttl, rdata );
}
示例15: getTXTRecord
import org.xbill.DNS.TXTRecord; //导入依赖的package包/类
public static TXTRecord getTXTRecord(String hostName) {
return null;
}