Created
January 28, 2017 12:40
-
-
Save iwconfig/056a4f22e14fcd7775519d642d9f3e31 to your computer and use it in GitHub Desktop.
barebone bash downloader
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
## http://unix.stackexchange.com/a/83927 | |
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