lib/dns.sh

719 B · 27 lines · bash

1#!/usr/bin/env bash
2
3brt_dns() {
4 local host="${1:-}"
5 local rtype="${2:-A}"
6
7 if [[ -z "$host" ]]; then
8 brt_error "Usage: brt -dns <host> [A|AAAA|MX|TXT|NS|CNAME|SOA|PTR|ANY]"
9 exit 1
10 fi
11
12 rtype=$(echo "$rtype" | tr '[:lower:]' '[:upper:]')
13
14 if command -v dig &>/dev/null; then
15 brt_info "DNS lookup: ${host} (${rtype})"
16 dig +short "$host" "$rtype" 2>/dev/null || dig "$host" "$rtype"
17 elif command -v nslookup &>/dev/null; then
18 brt_info "DNS lookup: ${host}"
19 nslookup -type="$rtype" "$host" 2>/dev/null || nslookup "$host"
20 elif command -v host &>/dev/null; then
21 host -t "$rtype" "$host"
22 else
23 brt_error "No DNS tool found (dig, nslookup, or host required)"
24 exit 1
25 fi
26}
27