-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDomainList
executable file
·73 lines (61 loc) · 1.77 KB
/
getDomainList
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
SSLPATH=/etc/nginx/ssl
if [ -z "$SITESPATH" ]; then
if [ -d "/etc/nginx/sites-enabled" ]; then
SITESPATH="/etc/nginx/sites-enabled"
elif [ -d "sites-enabled" ]; then
SITESPATH="sites-enabled"
else
echo "No valid directory found for SITESPATH."
exit 1
fi
fi
if [ -z "$SSLPATH" ]; then
if [ -d "ssl" ]; then
SSLPATH="ssl"
elif [ -d "/etc/nginx/ssl" ]; then
SSLPATH="/etc/nginx/ssl"
else
echo "No valid directory found for SSLPATH."
# exit 1
fi
fi
if [[ ! -z "$SSLPATH" ]] && [[ -d "$SSLPATH" || -f "$SSLPATH" ]]; then
hours_old=$((($(date +%s)-$(date -r /etc/nginx/ssl/nginx.key +%s))/(60*60)))
echo "Hours since last key $hours_old"
if [ $hours_old -lt 1 ]; then
echo "nothing to do"
exit 0
fi
fi
anyFailures=0
for f in $SITESPATH/*
do
domains=$(grep -oP '(?<=server_name\s).*(?=;)' $f)
IFS=' ' read -r -a array <<< "$domains"
for domain in "${array[@]}"
do
if [[ "$DOMAIN_LIST" != *"-d $domain"* ]]; then # Add if not a duplicate domain
# Fetch the first A (IPv4) record
ipv4_address=$(dig A $domain +short | head -n 1)
# Fetch the first AAAA (IPv6) record
ipv6_address=$(dig AAAA $domain +short | head -n 1)
if [ -z "$ipv4_address" ] && [ -z "$ipv6_address" ]; then
echo "$domain - FAILED DNS"
anyFailures=1
else
printf "%-30s - IPv4: %s, IPv6: %s\n" "$domain" "$ipv4_address" "$ipv6_address"
DOMAIN_LIST+="-d $domain "
fi
fi
done
done
if [ -z "$DOMAIN_LIST" ]; then
echo "No host domains found."
exit 1
elif [ "$anyFailures" -eq 1 ]; then
echo "There were failures in DNS resolution."
exit 1
else
echo $DOMAIN_LIST
fi