Skip to content

Instantly share code, notes, and snippets.

@lirlia
Created July 12, 2021 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lirlia/dafb2e8d021f1156fc47693873f0d4b6 to your computer and use it in GitHub Desktop.
Save lirlia/dafb2e8d021f1156fc47693873f0d4b6 to your computer and use it in GitHub Desktop.
function kurl() {
# URLをパース
read proto server path <<<$(echo ${1//// })
DOC=/${path// //}
HOST=${server//:*}
PORT=${server//*:}
[[ x"${HOST}" == x"${PORT}" ]] && PORT=80
# /dev/tcp/~をfd3で開く
exec 3<>/dev/tcp/${HOST}/$PORT
# HTTPリクエストを送る
echo -en "GET ${DOC} HTTP/1.0\r\nHost: ${HOST}\r\n\r\n" >&3
# レスポンスを読み取る
(while read line; do
[[ "$line" == $'\r' ]] && break
done && cat) <&3
# #3 fdをクローズする
exec 3>&-
}
@lirlia
Copy link
Author

lirlia commented Jul 12, 2021

This script is download file from HTTP.

You can use this command like kurl http://mysite:8000/myscript.sh.
This script isn't adopt HTTPS.

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