Skip to content

Instantly share code, notes, and snippets.

@gbonk
Created October 10, 2021 22:26
Show Gist options
  • Save gbonk/e1b00150e55b5cb10832c492da611a42 to your computer and use it in GitHub Desktop.
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
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"
@spirillen
Copy link

You should by the way be able to replace this line

if [[ -z $1 ]]; then
  echo "a domain.tld is required"
  exit 1
fi

with

if [[ -z $1 ]]; then
  echo "a domain.tld is required"
  exec bash "${0}" && exit
fi

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:

image

Also commented here: https://mypdns.org/my-privacy-dns/porn-records/-/issues/1289#note_21240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment