当前位置: 首页>>代码示例>>Java>>正文


Java ReverseMap类代码示例

本文整理汇总了Java中org.xbill.DNS.ReverseMap的典型用法代码示例。如果您正苦于以下问题:Java ReverseMap类的具体用法?Java ReverseMap怎么用?Java ReverseMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReverseMap类属于org.xbill.DNS包,在下文中一共展示了ReverseMap类的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;
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:24,代码来源:Helperfunctions.java

示例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;
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:31,代码来源:DNSLookupService.java

示例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];
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:DnsRecordConverter.java

示例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);
        }
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:17,代码来源:ReverseDnsProvisioningAdapter.java

示例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;
}
 
开发者ID:cert-se,项目名称:megatron-java,代码行数:20,代码来源:IpAddressUtil.java

示例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();
}
 
开发者ID:samuelhehe,项目名称:androidpn_enhanced_client,代码行数:14,代码来源:DNSJavaNameService.java

示例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();
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:15,代码来源:DNSJavaNameService.java

示例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;
}
 
开发者ID:twachan,项目名称:James,代码行数:17,代码来源:DNSJavaService.java

示例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;
}
 
开发者ID:cert-se,项目名称:megatron-java,代码行数:13,代码来源:IpAddressUtil.java


注:本文中的org.xbill.DNS.ReverseMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。