-
-
Save QROkes/534624d9fc4b76ccc5e0a769d6c821cd to your computer and use it in GitHub Desktop.
Check if domain name is subdomain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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