Created
October 10, 2021 22:26
-
-
Save gbonk/e1b00150e55b5cb10832c492da611a42 to your computer and use it in GitHub Desktop.
Something that helps to check if a website uses www or not via redirect
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
if [[ -z $1 ]]; then | |
echo "a domain.tld is required" | |
exit 1 | |
fi | |
domain="$1" | |
URL_WO="$domain" | |
URL_W="www.$domain" | |
STATUSCODE_WO=$(curl --silent --output /dev/null --write-out "%{http_code}" "https://$URL_WO") | |
STATUSCODE_W=$(curl --silent --output /dev/null --write-out "%{http_code}" "https://$URL_W") | |
if [[ $STATUSCODE_W == 200 ]] && [[ $STATUSCODE_WO != 200 ]]; then | |
echo "$URL_W" | |
elif [[ $STATUSCODE_W != 200 ]] && [[ $STATUSCODE_WO == 200 ]]; then | |
echo "- $URL_W" | |
elif [[ $STATUSCODE_W == 200 ]] && [[ $STATUSCODE_WO == 200 ]]; then | |
echo "+ $URL_W" | |
else | |
echo "Whoops" | |
exit 2 | |
fi | |
if [[ $STATUSCODE_W == 200 ]]; then | |
$(curl --silent -o '/tmp/live.txt' "https://$URL_W") | |
elif [[ $STATUSCODE_WO == 200 ]]; then | |
$(curl --silent -o '/tmp/live.txt' "https://$URL_WO") | |
else | |
echo "Hmmm" | |
exit 3 | |
fi | |
# This oneliner will sort all records obtained | |
cat /tmp/live.txt | grep -o '<a .*href=.*>' | sed -e 's/<a /\n<a /g' | sed -e 's/<a .*href=['"'"'"]//' -e 's/["'"'"'].*$//' -e '/^$/ d' | awk -F[/:] '{print $4}' | sort -u | grep "$domain" | |
cat /tmp/live.txt | grep -o '<img .*src=.*>' | sed -e 's/<a /\n<a /g' | sed -e 's/<img .*src=['"'"'"]//' -e 's/["'"'"'].*$//' -e '/^$/ d' | awk -F[/:] '{print $4}' | sort -u | grep "$domain" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should by the way be able to replace this line
with
The exec command will load a new instance of script
"${0}"
(This script) and exit current, that will make you a loop until satisfied.You see the idea here:
Also commented here: https://mypdns.org/my-privacy-dns/porn-records/-/issues/1289#note_21240