Skip to content

Instantly share code, notes, and snippets.

@QROkes
Created April 7, 2019 21:58
Show Gist options
  • Save QROkes/534624d9fc4b76ccc5e0a769d6c821cd to your computer and use it in GitHub Desktop.
Save QROkes/534624d9fc4b76ccc5e0a769d6c821cd to your computer and use it in GitHub Desktop.
Check if domain name is subdomain
# Check if domain is subdomain
if [[ -n $domain ]]; then
count=1
while true; do
tld=$(echo "${domain}" | rev | cut -d'.' -f -$count -s | rev)
if ! grep -Fxq "$tld" /opt/webinoly/lib/public_suffix_list.dat; then
break
fi
count=$[$count+1]
done
[[ -n $(echo "$(echo "${domain}" | rev | cut -d'.' -f $count- -s | rev)" | cut -d'.' -f 2 -s) || $count == 1 ]] && echo "Is subdomain" || echo "Not subdomain"
fi
# Obtain the full list from here: https://publicsuffix.org - needed to recognize only valid TLD's.
com
com.mx
mx
gov
org
net
edu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment