Created
December 2, 2016 16:12
-
-
Save puckbag/e7e76349faef5237d104368a9613978c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
## | |
## Usage: | |
## http-response-headers.sh 'http://www.example.com/test/' '127.0.0.1' | |
## | |
#!/usr/bin/env bash | |
URL="$1" | |
IP="$2" | |
## http://stackoverflow.com/a/6174447 | |
# extract the protocol | |
proto="$(echo $URL | grep :// | sed -e's,^\(.*://\).*,\1,g')" | |
# remove the protocol -- updated | |
url=$(echo $URL | sed -e s,$proto,,g) | |
# extract the user (if any) | |
user="$(echo $url | grep @ | cut -d@ -f1)" | |
# extract the host -- updated | |
host=$(echo $url | sed -e s,$user@,,g | cut -d/ -f1) | |
# by request - try to extract the port | |
port="$(echo $host | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')" | |
host="$(echo $host | sed -e 's,:\([0-9]*\).*$,,g')" | |
# extract the path (if any) | |
path="$(echo $url | grep / | cut -d/ -f2-)" | |
#echo "url: $url" | |
#echo " proto: $proto" | |
#echo " user: $user" | |
#echo " host: $host" | |
#echo " port: $port" | |
#echo " path: $path" | |
IP_URL="$proto" | |
if [ -n "$user" ]; then | |
IP_URL="$IP_URL$user@" | |
fi | |
IP_URL="$IP_URL$IP" | |
if [ -n "$port" ]; then | |
IP_URL="$IP_URL:$port" | |
fi | |
IP_URL="$IP_URL/$path" | |
echo | |
curl --silent -v -k -H"Host: $host" "$IP_URL" 2>&1 >/dev/null | grep '^<' | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment