Created
August 3, 2015 11:56
-
-
Save ety001/651c6e3a3503e23fc07c 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
function __wget() { | |
: ${DEBUG:=0} | |
local URL=$1 | |
local tag="Connection: close" | |
local mark=0 | |
if [ -z "${URL}" ]; then | |
printf "Usage: %s \"URL\" [e.g.: %s http://www.google.com/]" \ | |
"${FUNCNAME[0]}" "${FUNCNAME[0]}" | |
return 1; | |
fi | |
read proto server path <<<$(echo ${URL//// }) | |
DOC=/${path// //} | |
HOST=${server//:*} | |
PORT=${server//*:} | |
[[ x"${HOST}" == x"${PORT}" ]] && PORT=80 | |
[[ $DEBUG -eq 1 ]] && echo "HOST=$HOST" | |
[[ $DEBUG -eq 1 ]] && echo "PORT=$PORT" | |
[[ $DEBUG -eq 1 ]] && echo "DOC =$DOC" | |
exec 3<>/dev/tcp/${HOST}/$PORT | |
echo -en "GET ${DOC} HTTP/1.1\r\nHost: ${HOST}\r\n${tag}\r\n\r\n" >&3 | |
while read line; do | |
[[ $mark -eq 1 ]] && echo $line | |
if [[ "${line}" =~ "${tag}" ]]; then | |
mark=1 | |
fi | |
done <&3 | |
exec 3>&- | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment