-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_page
More file actions
executable file
·28 lines (22 loc) · 920 Bytes
/
web_page
File metadata and controls
executable file
·28 lines (22 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
echo "WARNING: web-page is a misnomer until I implement querying anything but root doc on domain"
# based on recipe "Using bash Net-Redirection"
# in "bash Cookbook" (O'Reilly)
if [[ $# -lt 1 ]]; then
echo "$(basename "$0") web_address"
echo " GETs the web page at web_address and prints it to stdout."
exit 1
fi
# note must be careful of quotes in python3 call, so $1 will expand
DOMAIN=$(python3 -c "from urllib.parse import urlsplit;print(urlsplit(\"$1\").netloc)")
REST=$(python3 -c "from urllib.parse import urlsplit;print(\"{path}?{query}\".format(urlsplit(\"$1\").path))")
echo "$REST"
exit
# TODO: split out domain from URL, use /dev/tcp/$DOMAIN, then
# GET $REST
# set up file descriptor 3 as temporary stream tied to web page
exec 3<> "/dev/tcp/${1##http://}/80"
# request page
echo -e "GET / HTTP/1.0\n" >&3
# print temporary stream to stdout and close
cat <&3-