Skip to content

Instantly share code, notes, and snippets.

@agneevX
Last active February 26, 2022 05:57
Show Gist options
  • Save agneevX/92a45fa0820bc90fc823fbf0edad9c34 to your computer and use it in GitHub Desktop.
Save agneevX/92a45fa0820bc90fc823fbf0edad9c34 to your computer and use it in GitHub Desktop.
Bash script to send quers tr
#
# To execute
# ./dns.sh google.com
#
# 69.69.69.69, 70.70.70.70, 71.71.71.71 are example IPs for ISP DNS servers
#
# Common CDNs to test for:
#
# se2.itunes.apple.com -> Akamai CDN
# i.scdn.co -> Fastly CDN
# alexa.amazon.co.in -> Cloudfront CDN
# labtest-gartner.lldns.net -> Limelight CDN
#!/bin/bash
dns_servers=(oc-bom1 69.69.69.69 70.70.70.70 71.71.71.71 8.8.8.8 1.1.1.1)
for i in "${dns_servers[@]}"; do
echo "+ ---- $i ---- +"
# ISP's DNS servers here...
if [[ $i == "69.69.69.69" ]] || [[ $i == "70.70.70.70" ]] || [[ $i == "71.71.71.71" ]]; then
a=$(kdig +short @$i "$1")
# Using alternate port for Quad9
elif [[ $i == "9.9.9.11" ]]; then
a=$(kdig +short -p 9953 @$i "$1")
# for cloud VMs, specify port after query, e.g. ./dns.sh google.com 4300
elif [[ $i == "oc-bom1" ]] || [[ $i == "oracle1" ]]; then
if [[ ! "$2" ]]; then
printf "No port specified. Defaulting to port 1100\n\n"
a=$(dig +short @$i -p 1100 "$1" )
else
a=$(dig +stats +short @$i -p $2 "$1" )
fi
# Send query without ECS, usage: ./dns.sh google.com no-ecs
elif [[ $2 == "no-ecs" ]]; then
echo "Using 0.0.0.0/0 as ECS data"
a=$(kdig +short +tls +subnet=0.0.0.0/0 @$i "$1")
# Send queries over DNS-over-TLS; to mitigate ISP DNS redirection
# If your ISP does not do this, you can remove the +tls flag
else
a=$(kdig +short +tls @$i "$1")
fi
echo "$a"
ping -c 1 -W 1 $(echo "$a" | tail -n1) | grep icmp
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment