本文整理汇总了Java中org.xbill.DNS.ReverseMap.fromAddress方法的典型用法代码示例。如果您正苦于以下问题:Java ReverseMap.fromAddress方法的具体用法?Java ReverseMap.fromAddress怎么用?Java ReverseMap.fromAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xbill.DNS.ReverseMap
的用法示例。
在下文中一共展示了ReverseMap.fromAddress方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reverseDNSLookup
import org.xbill.DNS.ReverseMap; //导入方法依赖的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;
}
示例2: dnsLookup
import org.xbill.DNS.ReverseMap; //导入方法依赖的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;
}
示例3: toRecord
import org.xbill.DNS.ReverseMap; //导入方法依赖的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];
}
}
示例4: doUpdate
import org.xbill.DNS.ReverseMap; //导入方法依赖的package包/类
private void doUpdate(AdapterOperation op) {
log().debug("doUpdate: operation: " + op.getType().name());
for (ReverseDnsRecord record : m_reverseDnsProvisioningAdapterService.get(op.getNodeId()) ) {
log().debug("doUpdate: ReverseDnsRecord: hostname: " + record.getHostname() + " zone: " + record.getZone() + " ip address: " + record.getIp().getHostAddress());
try {
Update update = new Update(Name.fromString(record.getZone()));
Name ptrRecord=ReverseMap.fromAddress(record.getIp());
update.replace(ptrRecord, Type.PTR, 3600, record.getHostname());
m_resolver.send(update);
m_reverseDnsProvisioningAdapterService.update(op.getNodeId(),record);
} catch (Exception e) {
log().error("updateNode: Error handling updated event.", e);
sendAndThrow(op.getNodeId(), e);
}
}
}
示例5: reverseDnsLookupUsingDnsJavaSimpleResolver
import org.xbill.DNS.ReverseMap; //导入方法依赖的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;
}
示例6: getHostByAddr
import org.xbill.DNS.ReverseMap; //导入方法依赖的package包/类
/**
* Performs a reverse DNS lookup.
* @param addr The ip address to lookup.
* @return The host name found for the ip address.
*/
public String
getHostByAddr(byte [] addr) throws UnknownHostException {
Name name = ReverseMap.fromAddress(InetAddress.getByAddress(addr));
Record [] records = new Lookup(name, Type.PTR).run();
if (records == null)
throw new UnknownHostException();
return ((PTRRecord) records[0]).getTarget().toString();
}
示例7: getHostByAddr
import org.xbill.DNS.ReverseMap; //导入方法依赖的package包/类
/**
* Performs a reverse DNS lookup.
*
* @param addr
* The ip address to lookup.
* @return The host name found for the ip address.
*/
public String getHostByAddr(byte[] addr) throws UnknownHostException {
Name name = ReverseMap.fromAddress(InetAddress.getByAddress(addr));
Record[] records = new Lookup(name, Type.PTR).run();
if (records == null)
throw new UnknownHostException();
return ((PTRRecord) records[0]).getTarget().toString();
}
示例8: getHostName
import org.xbill.DNS.ReverseMap; //导入方法依赖的package包/类
/**
* @see org.apache.james.dnsservice.api.DNSService#getHostName(java.net.InetAddress)
*/
public String getHostName(InetAddress addr) {
String result = null;
Name name = ReverseMap.fromAddress(addr);
Record[] records = lookupNoException(name.toString(), Type.PTR, "PTR");
if (records == null) {
result = addr.getHostAddress();
} else {
PTRRecord ptr = (PTRRecord) records[0];
result = ptr.getTarget().toString();
}
return result;
}
示例9: reverseDnsLookupUsingDnsJavaExtendedResolver
import org.xbill.DNS.ReverseMap; //导入方法依赖的package包/类
private static String reverseDnsLookupUsingDnsJavaExtendedResolver(long ipAddress) throws UnknownHostException {
byte[] address = convertLongAddressToBuf(ipAddress);
Name name = ReverseMap.fromAddress(InetAddress.getByAddress(address));
Record[] records = new Lookup(name, Type.PTR).run();
if (records == null) {
throw new UnknownHostException();
}
String result = ((PTRRecord)records[0]).getTarget().toString();
// remove trailing "."
result = result.endsWith(".") ? result.substring(0, result.length() - 1) : result;
return result;
}