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


Java ARecord类代码示例

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


ARecord类属于org.xbill.DNS包,在下文中一共展示了ARecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolve

import org.xbill.DNS.ARecord; //导入依赖的package包/类
public static String resolve(String host, int addrType) {
    try {
        Lookup lookup = new Lookup(host, addrType);
        SimpleResolver resolver = new SimpleResolver("114.114.114.114");
        resolver.setTimeout(5);
        lookup.setResolver(resolver);
        Record[] result = lookup.run();
        if (result == null) return null;

        List<Record> records = java.util.Arrays.asList(result);
        java.util.Collections.shuffle(records);
        for (Record record : records) {
            if (addrType == Type.A) {
                return ((ARecord) record).getAddress().getHostAddress();
            } else if (addrType == Type.AAAA) {
                return ((AAAARecord) record).getAddress().getHostAddress();
            }
        }

    } catch (Exception ex) {
        return null;
    }

    return null;
}
 
开发者ID:lparam,项目名称:xTun-android,代码行数:26,代码来源:Utils.java

示例2: testSentMessageTooLongThrowsException

import org.xbill.DNS.ARecord; //导入依赖的package包/类
@Test
public void testSentMessageTooLongThrowsException() throws Exception {
  Update oversize = new Update(Name.fromString("tld", Name.root));
  for (int i = 0; i < 2000; i++) {
    oversize.add(
        ARecord.newRecord(
            Name.fromString("test-extremely-long-name-" + i + ".tld", Name.root),
            Type.A,
            DClass.IN));
  }
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  when(mockSocket.getOutputStream()).thenReturn(outputStream);
  IllegalArgumentException thrown =
      expectThrows(IllegalArgumentException.class, () -> resolver.send(oversize));
  assertThat(thrown).hasMessageThat().contains("message larger than maximum");
}
 
开发者ID:google,项目名称:nomulus,代码行数:17,代码来源:DnsMessageTransportTest.java

示例3: resolveHostByName

import org.xbill.DNS.ARecord; //导入依赖的package包/类
/**
 * resolves an A record by its name using a specified DNS host and port
 *
 * @param resolverHost name server hostname or IP address
 * @param resolverPort name server port
 * @param name         the DNS name of the A record - the name to resolve
 * @return a comma separated list of IP addresses or an empty string when unable to resolve
 */
public String resolveHostByName(String resolverHost, int resolverPort, String name) {
    try {
        SimpleResolver resolver = new SimpleResolver(resolverHost);
        resolver.setPort(resolverPort);

        Lookup lookup = new Lookup(name, A);
        Record[] records = lookup.run();
        if (records != null) {
            List<String> addresses =
                    of(records)
                            .filter(it -> it instanceof ARecord)
                            .map(it -> ((ARecord) it).getAddress().getHostAddress())
                            .collect(toList());

            return collectionToCommaDelimitedString(addresses);
        } else {
            return "";
        }
    } catch (UnknownHostException | TextParseException e) {
        log.warn("unable to resolve using A record " + name, e);
        return "";
    }
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:32,代码来源:DnsResolver.java

示例4: getDynamicMap

import org.xbill.DNS.ARecord; //导入依赖的package包/类
private static HashMap<String, String> getDynamicMap() {
	HashMap<String, String> dynamicMap = new HashMap<>();
	aDynamics.forEach((host, records) -> {
		StringBuilder sb = new StringBuilder();
		for (Record record : records) {
			if (record instanceof ARecord) {
				sb.append(((ARecord) record).getAddress().getHostAddress());
			} else if (record instanceof CNAMERecord) {
				sb.append(((CNAMERecord) record).getTarget().
						toString(true).toLowerCase());
			}
			sb.append(',');
		}
		dynamicMap.put(host, sb.substring(0, Math.max(sb.length() - 1, 0)));
	});
	return dynamicMap;
}
 
开发者ID:xqbase,项目名称:ddns,代码行数:18,代码来源:DDNS.java

示例5: testQueryAddresses

import org.xbill.DNS.ARecord; //导入依赖的package包/类
@Test
public void testQueryAddresses() throws SendException {
    new Expectations() {
        {
            lookup.run();
            result =
                    new Record[] {
                            new ARecord(HOST1_EXAMPLE_COM_NAME, 0, 0, IP1),
                            new ARecord(HOST1_EXAMPLE_COM_NAME, 0, 0, IP2)

                    };

        }
    };

    InetAddress[] addresses =
            addressLookup.queryAddresses(HOST1_EXAMPLE_COM_NAME);

    InetAddress[] expected = new InetAddress[] { IP1, IP2 };
    assertArrayEquals(expected, addresses);
}
 
开发者ID:hontvari,项目名称:mireka,代码行数:22,代码来源:AddressLookupTest.java

示例6: findAddresses

import org.xbill.DNS.ARecord; //导入依赖的package包/类
private String[] findAddresses(Name target, Record[] records) {
	ArrayList<String> addresses = new ArrayList<String>();
	for (Record record : records) {
		if (target == null || target.equals(record.getName())) {
			int recordType = record.getType();
			if (Type.A == recordType)
				addresses.add(((ARecord)record).getAddress().getHostAddress());
			else if (Type.AAAA == recordType)
				addresses.add(((AAAARecord)record).getAddress().getHostAddress());
		}
	}

	if (addresses.size() == 0)
		return null;
	return addresses.toArray(new String[addresses.size()]);
}
 
开发者ID:wnagele,项目名称:dnsjava-recursive-resolver,代码行数:17,代码来源:RecursiveResolver.java

示例7: getARecord

import org.xbill.DNS.ARecord; //导入依赖的package包/类
public static List<ForwardLookupResult> getARecord(String hostName, String domainName) throws TextParseException {
    List<ForwardLookupResult> entries = null;
    if (hostName != null && !hostName.isEmpty() && domainName != null && !domainName.isEmpty()) {
        Record[] recs = new Lookup(hostName, Type.A).run();
        if (recs != null) {
            if (recs.length > 0) {
                entries = new ArrayList<>();
                for (Record record : recs) {
                    ForwardLookupResult foundSubDomain = new ForwardLookupResult(domainName);
                    foundSubDomain.setHostName(hostName);
                    String ipAddress = ((ARecord) record).getAddress().getHostAddress();
                    foundSubDomain.setIpAddress(ipAddress);
                    foundSubDomain.setLookupType("A");
                    entries.add(foundSubDomain);
                }
            }
        }
    }
    return entries;
}
 
开发者ID:sensepost,项目名称:yeti,代码行数:21,代码来源:ForwardLookupHelper.java

示例8: getARecord

import org.xbill.DNS.ARecord; //导入依赖的package包/类
public static List<ARecordResult> getARecord(String hostName) throws TextParseException {
    List<ARecordResult> entries = null;

    Record[] recs = new Lookup(hostName, Type.A).run();
    if (recs != null) {
        if (recs.length > 0) {
            entries = new ArrayList<>();
            for (Record record : recs) {
                ARecordResult foundSubDomain = new ARecordResult(NetworkTools.getDomainFromHost(hostName));
                foundSubDomain.setHostName(hostName);
                String ipAddress = ((ARecord) record).getAddress().getHostAddress();
                foundSubDomain.setIpAddress(ipAddress);
                foundSubDomain.setLookupType("A");
                entries.add(foundSubDomain);
            }
        }
    }

    return entries;
}
 
开发者ID:sensepost,项目名称:yeti,代码行数:21,代码来源:DNS.java

示例9: getARecord

import org.xbill.DNS.ARecord; //导入依赖的package包/类
public List<ARecordResult> getARecord(String hostName) throws TextParseException {
    List<ARecordResult> entries = null;

    Record[] recs = new Lookup(hostName, Type.A).run();
    if (recs != null) {
        if (recs.length > 0) {
            entries = new ArrayList<>();
            for (Record record : recs) {
                ARecordResult foundSubDomain = new ARecordResult(NetworkTools.getDomainFromHost(hostName));
                foundSubDomain.setHostName(hostName);
                String ipAddress = ((ARecord) record).getAddress().getHostAddress();
                foundSubDomain.setIpAddress(ipAddress);
                foundSubDomain.setLookupType("A");
                entries.add(foundSubDomain);
            }
        }
    }

    return entries;
}
 
开发者ID:sensepost,项目名称:yeti,代码行数:21,代码来源:DataAPI.java

示例10: testUnsignedThatMustBeSigned

import org.xbill.DNS.ARecord; //导入依赖的package包/类
@Test
public void testUnsignedThatMustBeSigned() throws IOException {
    Name query = Name.fromString("www.ingotronic.ch.");

    // prepare a faked, unsigned response message that must have a signature
    // to be valid
    Message message = new Message();
    message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION);
    message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER);
    add("www.ingotronic.ch./A", message);

    Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
    assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
    assertEquals(Rcode.SERVFAIL, response.getRcode());
    assertEquals("validate.bogus.missingsig", getReason(response));
}
 
开发者ID:ibauersachs,项目名称:dnssecjava,代码行数:17,代码来源:TestInvalid.java

示例11: testModifiedSignature

import org.xbill.DNS.ARecord; //导入依赖的package包/类
@Test
public void testModifiedSignature() throws IOException {
    Name query = Name.fromString("www.ingotronic.ch.");

    // prepare a faked, unsigned response message that must have a signature
    // to be valid
    Message message = new Message();
    message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION);
    message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER);
    message.addRecord(new RRSIGRecord(query, DClass.IN, 0, Type.A, Algorithm.RSASHA256, 5, new Date(System.currentTimeMillis() + 5000), new Date(System.currentTimeMillis() - 5000), 1234, Name.fromString("ingotronic.ch."), new byte[] { 1, 2, 3 }), Section.ANSWER);
    add("www.ingotronic.ch./A", message);

    Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
    assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
    assertEquals(Rcode.SERVFAIL, response.getRcode());
    assertTrue(getReason(response).startsWith("failed.answer.positive:{ www.ingotronic.ch."));
}
 
开发者ID:ibauersachs,项目名称:dnssecjava,代码行数:18,代码来源:TestInvalid.java

示例12: getByName

import org.xbill.DNS.ARecord; //导入依赖的package包/类
/**
 * @see org.apache.james.dnsservice.api.DNSService#getByName(String)
 */
public InetAddress getByName(String host) throws UnknownHostException {
    String name = allowIPLiteral(host);

    try {
        // Check if its local
        if (name.equalsIgnoreCase(localHostName) || name.equalsIgnoreCase(localCanonicalHostName) || name.equals(localAddress)) {
            return getLocalHost();
        }

        return org.xbill.DNS.Address.getByAddress(name);
    } catch (UnknownHostException e) {
        Record[] records = lookupNoException(name, Type.A, "A");

        if (records != null && records.length >= 1) {
            ARecord a = (ARecord) records[0];
            return InetAddress.getByAddress(name, a.getAddress().getAddress());
        } else
            throw e;
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:24,代码来源:DNSJavaService.java

示例13: getAllByName

import org.xbill.DNS.ARecord; //导入依赖的package包/类
/**
 * @see org.apache.james.dnsservice.api.DNSService#getAllByName(String)
 */
public InetAddress[] getAllByName(String host) throws UnknownHostException {
    String name = allowIPLiteral(host);
    try {
        // Check if its local
        if (name.equalsIgnoreCase(localHostName) || name.equalsIgnoreCase(localCanonicalHostName) || name.equals(localAddress)) {
            return new InetAddress[] { getLocalHost() };
        }

        InetAddress addr = org.xbill.DNS.Address.getByAddress(name);
        return new InetAddress[] { addr };
    } catch (UnknownHostException e) {
        Record[] records = lookupNoException(name, Type.A, "A");

        if (records != null && records.length >= 1) {
            InetAddress[] addrs = new InetAddress[records.length];
            for (int i = 0; i < records.length; i++) {
                ARecord a = (ARecord) records[i];
                addrs[i] = InetAddress.getByAddress(name, a.getAddress().getAddress());
            }
            return addrs;
        } else
            throw e;
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:28,代码来源:DNSJavaService.java

示例14: testDnsQuery

import org.xbill.DNS.ARecord; //导入依赖的package包/类
@Test
public void testDnsQuery() throws Exception {
    Message message = Message.newQuery(new ARecord(new Name("notblocked.example.com."),
            0x01,
            3600,
            Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
    ));

    UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
            .srcPort(UdpPort.DOMAIN)
            .dstPort(UdpPort.DOMAIN)
            .srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(message.toWire())
            );

    IpPacket ipOutPacket = new IpV4Packet.Builder()
            .version(IpVersion.IPV4)
            .tos(IpV4Rfc791Tos.newInstance((byte) 0))
            .protocol(IpNumber.UDP)
            .srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(payLoadBuilder)
            .build();

    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());

    assertNull(mockEventLoop.lastResponse);
    assertNotNull(mockEventLoop.lastOutgoing);
    assertEquals(Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}), mockEventLoop.lastOutgoing.getAddress());
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:38,代码来源:DnsPacketProxyTest.java

示例15: requestLookup

import org.xbill.DNS.ARecord; //导入依赖的package包/类
/**
 * Sends DNS request via system or custom DNS resolver
 */
private InetAddress[] requestLookup(String host) throws UnknownHostException {
    InetAddress[] addresses = null;
    if (isCustomResolver() && ((ExtendedResolver) resolver).getResolvers().length > 0) {
        try {
            Lookup lookup = new Lookup(host, Type.A);
            lookup.setCache(lookupCache);
            if (timeoutMs > 0) {
                resolver.setTimeout(timeoutMs / 1000, timeoutMs % 1000);
            }
            lookup.setResolver(resolver);
            Record[] records = lookup.run();
            if (records == null || records.length == 0) {
                throw new UnknownHostException("Failed to resolve host name: " + host);
            }
            addresses = new InetAddress[records.length];
            for (int i = 0; i < records.length; i++) {
                addresses[i] = ((ARecord) records[i]).getAddress();
            }
        } catch (TextParseException tpe) {
            log.debug("Failed to create Lookup object: " + tpe);
        }
    } else {
        addresses = systemDefaultDnsResolver.resolve(host);
        if (log.isDebugEnabled()) {
            log.debug("Cache miss: " + host + " Thread #" + JMeterContextService.getContext().getThreadNum()
                    + ", resolved with system resolver into " + Arrays.toString(addresses));
        }
    }
    return addresses;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:34,代码来源:DNSCacheManager.java


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