about summary refs log tree commit diff stats
path: root/scripts/get_dns.sh
blob: 2d82925ee70f864fdad5a6884b8bff02765a1f46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env nix-shell
#! nix-shell -p dig -p dash -i dash --impure
# shellcheck shell=dash

get_dns_types() {
    cat <<EOF
    A
    AAAA
    CAA
    CNAME
    DNAME
    MX
    NS
    SOA
    SRV
    TXT
    PTR
    DNSKEY
    DS
    SSHFP
    TLSA
    OPENPGPKEY
    SVCB
    HTTPS
EOF
}

check_type() {
    domain="$1"
    type="$2"

    if [ "$(dig +short -t "$type" "$domain" | wc -c)" -ne 0 ]; then
        dig +short -t "$type" "$domain" | while IFS="$(printf "\n")" read -r output; do
            printf "(%s) %s [%s]\n" "$type" "$output" "$domain"
        done
    else
        printf "(%s) <Not set> [%s]\n" "$type" "$domain"
    fi
}

get_dns() {
    original_domain="$1"

    get_dns_types | while read -r type; do
        check_type "$original_domain" "$type"
    done

    # DKIM
    check_type "mail._domainkey.$original_domain" "TXT"

    # DMARC
    check_type "_dmarc.$original_domain" "TXT"
}

get_dns "$1"