HTTP GET

From Noah.org
Revision as of 04:48, 23 February 2010 by Root (talk | contribs) (Created page with 'Category: Engineering How many ways can you get a web page? This works in Bourne and Bash -- note that Bash `echo` behaves the opposite of Bourne! <pre> if echo -e | grep -…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search


How many ways can you get a web page?

This works in Bourne and Bash -- note that Bash `echo` behaves the opposite of Bourne!

if echo -e | grep -q -- -e; then
    echo "sh style"
    (echo 'GET /dotfiles HTTP/1.1\nHost: www.noah.org\n\n'; sleep 2 ) | telnet www.noah.org 80
else
    echo "Bash style"
    (echo -e 'GET /dotfiles HTTP/1.1\nHost: www.noah.org\n\n'; sleep 2 ) | telnet www.noah.org 80
fi

It's probably just as well to use multiple `echo` statements since this will work on both:

(echo 'GET /dotfiles HTTP/1.1';echo 'Host: www.noah.org';echo;echo; sleep 2 ) | telnet www.noah.org 80

You can do a similar thing with netcat (`nc`). Notice that the `telnet` version requires a `sleep` to give time for the data to come back whereas the `nc` version waits until the remove server closes the connection, so no `sleep` is necessary.

(echo 'GET /dotfiles HTTP/1.1';echo 'Host: www.noah.org';echo;echo) | nc www.noah.org 80