diff options
author | epoch <epoch@hack.thebackupbox.net> | 2020-02-05 15:50:19 +0000 |
---|---|---|
committer | epoch <epoch@hack.thebackupbox.net> | 2020-02-05 15:50:19 +0000 |
commit | b4b98598e1dadfcb1591b02de9d7add7b27ae056 (patch) | |
tree | 534ade870417545aca8737748067e727af03a044 /urititle | |
parent | 3f98b2883c0b71a053584c7647321536236289b0 (diff) | |
download | uritools-b4b98598e1dadfcb1591b02de9d7add7b27ae056.tar.gz uritools-b4b98598e1dadfcb1591b02de9d7add7b27ae056.zip |
added urititle because I use this script on multiple computers
Diffstat (limited to 'urititle')
-rwxr-xr-x | urititle | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/urititle b/urititle new file mode 100755 index 0000000..263ffb2 --- /dev/null +++ b/urititle @@ -0,0 +1,37 @@ +#!/bin/sh +scheme=$(printf "%s\n" "$1" | uricut -s) +path=$(printf "%s\n" "$1" | uricut -p) +qs=$(printf "%s\n" "$1" | uricut -q) +domain=$(printf "%s\n" "$1" | uricut -d) +port=$(printf "%s\n" "$1" | uricut -P) +if [ ! "$port" ];then + if [ "$scheme" = "https" ];then + port=443 + SSL=--ssl + fi + if [ "$scheme" = "http" ];then + port=80 + fi +fi +if [ "$qs" ];then + path="${path}?${qs}" +fi +if [ "$port" ];then + UA="Mozilla/5.0 (impersonator)" +# content_type="$(printf "HEAD %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\n\r\n" "$path" "$domain" "$UA" | ncat -4 $SSL "$domain" "$port" | grep -i '^Content-Type: ' | head -n1 | cut '-d ' -f2 | cut '-d;' -f1 | tr -d '\r\n')" + a_header="$(curl -Lsi "$1" | egrep -ai '^Location: |^Content-Type: ' | head -n1 | tr -d '\r\n')" + if printf "%s\n" "${a_header}" | grep -i^Content-Type: 2>&1 >/dev/null 2>&1;then + content_type="$(printf '%s\n' "${a_header}" | cut '-d ' -f2- | cut -d; -f1)" + else + content_type="redirect probably" + fi + if [ "${content_type}" = "text/html" -o "${content_type}" = "application/xhtml+xml" ];then +# title="$(printf "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\n\r\n" "$path" "$domain" "$UA" | ncat -4 $SSL "$domain" "$port" | head -c 10000 | tr -d '\n' | tr '<' '\n' | grep -A 10 '^title>' | grep -B 10 '^\/title>' | cut '-d>' -f2)" + title="$(curl -si "$1" | head -c 10000 | tr -d '\n' | tr '<' '\n' | grep -iA 10 '^title' | grep -iB 10 '^\/title>' | cut '-d>' -f2 | sed 's/^ .//g' | sed 's/ .$//g' | grep .)" + printf "title: %s\n" "$title" | html_entities_decode + else + printf "%s\n" "${a_header}" + fi +else + printf "DONT KNOW HOW TO GET TITLE FOR THIS URL: %s\n" "$1" +fi |