Search in sources :

Example 1 with DNSRecord

use of net.sf.ivmaidns.dns.DNSRecord in project fqrouter by fqrouter.

the class DnsUtils method resolveA.

public static List<Inet4Address> resolveA(String domain, InetSocketAddress dnsServer) throws Exception {
    DNSMsgHeader qHeader = DNSMsgHeader.construct(DNSMsgHeader.QUERY, true, 1, 0, 0, 0, false);
    DNSRecord[] records = new DNSRecord[1];
    records[0] = new DNSRecord(new DNSName(domain, null), DNSRecord.A, DNSRecord.IN);
    byte[] query = DNSConnection.encode(qHeader, records);
    try {
        return resolveAOverUdp(dnsServer, query);
    } catch (Exception e) {
        LogUtils.e("failed to resolve over udp", e);
        return resolveAOverTcp(dnsServer, query);
    }
}
Also used : DNSMsgHeader(net.sf.ivmaidns.dns.DNSMsgHeader) DNSRecord(net.sf.ivmaidns.dns.DNSRecord) DNSName(net.sf.ivmaidns.dns.DNSName) IOException(java.io.IOException)

Example 2 with DNSRecord

use of net.sf.ivmaidns.dns.DNSRecord in project fqrouter by fqrouter.

the class DnsUtils method resolveTXT.

public static String resolveTXT(String domain, InetSocketAddress dnsServer) throws Exception {
    DNSMsgHeader qHeader = DNSMsgHeader.construct(DNSMsgHeader.QUERY, true, 1, 0, 0, 0, false);
    DNSRecord[] records = new DNSRecord[1];
    records[0] = new DNSRecord(new DNSName(domain, null), DNSRecord.TXT, DNSRecord.IN);
    byte[] request = DNSConnection.encode(qHeader, records);
    try {
        return resolveTXTOverUdp(dnsServer, request);
    } catch (Exception e) {
        LogUtils.e("failed to resolve txt over udp at " + dnsServer, e);
        return resolveTXTOverTcp(dnsServer, request);
    }
}
Also used : DNSMsgHeader(net.sf.ivmaidns.dns.DNSMsgHeader) DNSRecord(net.sf.ivmaidns.dns.DNSRecord) DNSName(net.sf.ivmaidns.dns.DNSName) IOException(java.io.IOException)

Example 3 with DNSRecord

use of net.sf.ivmaidns.dns.DNSRecord in project fqrouter by fqrouter.

the class DnsUtils method toIps.

private static List<Inet4Address> toIps(byte[] buffer) {
    DNSRecord[] records = DNSConnection.decode(buffer);
    List<Inet4Address> ips = new ArrayList<Inet4Address>();
    for (DNSRecord record : records) {
        if (DNSRecord.A == record.getRType()) {
            if (record.getRData().length > 0) {
                ips.add((Inet4Address) record.getRData()[0]);
            }
        }
    }
    return ips;
}
Also used : Inet4Address(java.net.Inet4Address) DNSRecord(net.sf.ivmaidns.dns.DNSRecord) ArrayList(java.util.ArrayList)

Aggregations

DNSRecord (net.sf.ivmaidns.dns.DNSRecord)3 IOException (java.io.IOException)2 DNSMsgHeader (net.sf.ivmaidns.dns.DNSMsgHeader)2 DNSName (net.sf.ivmaidns.dns.DNSName)2 Inet4Address (java.net.Inet4Address)1 ArrayList (java.util.ArrayList)1