Skip to content

Instantly share code, notes, and snippets.

@andrewimeson
Created December 31, 2018 20:18
Show Gist options
  • Save andrewimeson/0643bb0f0e91d830d0d58d128b8b15bd to your computer and use it in GitHub Desktop.
Save andrewimeson/0643bb0f0e91d830d0d58d128b8b15bd to your computer and use it in GitHub Desktop.
example of checking if domains are blocked using CleanBrowsing.org, which returns an NXDOMAIN with a special authority section upon block
#!/usr/bin/env bash
# Quick script to test if names are blocked using CleanBrowsing.org's Family
# Filter DNS servers
DNS_SERVER='185.228.168.168'
BLOCKED_AUTH="cleanbrowsing.rpz.noc.org."
domain_is_blocked() {
for name in "$@"; do
result=$(dig "$name" @${DNS_SERVER})
if echo "$result" | grep -q 'status: NXDOMAIN'; then
if echo "$result" | grep -A1 ';; AUTHORITY' | awk '{ print $5 }' |
grep "$BLOCKED_AUTH"; then
echo "Blocked: $name"
else
echo "Real NXDOMAINi: $name"
return 1
fi
else
echo "Not blocked: $name"
return 2
fi
done
}
# Functional tests
test_domain_is_blocked() {
if [ $# -ne 2 ]; then
echo "Expecting two arguments for test" >&2
return 2
fi
if
domain_is_blocked "$1" >/dev/null
[[ $? == "$2" ]]
then
echo 0
else
echo 1
return 1
fi
}
# Run some test cases
test_domain_is_blocked "reddit.com" "0"
test_domain_is_blocked "google.com" "2"
test_domain_is_blocked "sdfafdadsfjk.example.com" "1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment