2024-06-22 17:34:01 +10:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-06-22 19:26:38 +10:00
|
|
|
# Make log dir
|
|
|
|
mkdir -p logs
|
|
|
|
|
2024-06-22 17:34:01 +10:00
|
|
|
# Check if script has IP address as argument
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
# Get Node IPs
|
2024-06-22 17:55:42 +10:00
|
|
|
RESOLVED_IPS=$(kdig +short hnsdoh.com)
|
2024-06-22 17:34:01 +10:00
|
|
|
NODE_IPS=($RESOLVED_IPS)
|
|
|
|
if [ ${#NODE_IPS[@]} -eq 0 ]; then
|
|
|
|
echo "No IP addresses resolved for hnsdoh.com. Exiting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If script has IP address as argument, use that
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
# Add all arguments to NODE_IPS array
|
|
|
|
NODE_IPS=("$@")
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Define the domain and host for dig commands
|
|
|
|
TLS_HOST="hnsdoh.com"
|
|
|
|
DOH_URL="https://hnsdoh.com/dns-query"
|
|
|
|
|
|
|
|
# Function to check dig command result
|
|
|
|
check_dig() {
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "$(date) - $1 succeeded for NODE_IP=$NODE_IP"
|
|
|
|
else
|
|
|
|
echo "$(date) - $1 failed for NODE_IP=$NODE_IP"
|
|
|
|
# Save the failed IP
|
2024-06-22 19:26:38 +10:00
|
|
|
echo "$(date) - $1 failed for NODE_IP=$NODE_IP" >> logs/monitor.log
|
2024-06-22 17:34:01 +10:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Save test time
|
2024-06-22 19:26:38 +10:00
|
|
|
echo "Latest Check: $(date)" >> logs/monitor.log
|
2024-06-22 17:34:01 +10:00
|
|
|
|
|
|
|
|
|
|
|
# Loop over each IP and run the dig commands
|
|
|
|
for NODE_IP in "${NODE_IPS[@]}"
|
|
|
|
do
|
|
|
|
echo "$(date) - Running dig commands for NODE_IP=$NODE_IP"
|
|
|
|
|
|
|
|
# Run the dig commands
|
|
|
|
kdig +tls +tls-host=$TLS_HOST @$NODE_IP 1.wdbrn TXT +short
|
|
|
|
check_dig "kdig +tls"
|
|
|
|
|
|
|
|
kdig +tls-ca +https=@$DOH_URL @$NODE_IP 2.wdbrn TXT +short
|
|
|
|
check_dig "kdig +tls-ca +https"
|
|
|
|
|
|
|
|
kdig @$NODE_IP 3.wdbrn TXT +short
|
|
|
|
check_dig "kdig"
|
|
|
|
|
|
|
|
echo "$(date) - --------------------------------------------"
|
|
|
|
done
|