Tuesday, November 30, 2010

A Browser in Korn

Here's a quick tcpclient how-to implementing a simple web browser:

#!/usr/local/bin/ksh

printf "GET / HTTP/1.1\r\n" >&6
printf "Host: www.blogger.com\r\n" >&6
printf "User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.9.2.4) Gecko/20100630 Firefox/3.6.4\r\n" >&6
printf "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" >&6
printf "Accept-Language: en-us,en;q=0.5\r\n" >&6
printf "Accept-Encoding: gzip,deflate\r\n" >&6
printf "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" >&6
printf "Keep-Alive: 115\r\n" >&6
printf "Connection: close\r\n" >&6
printf "Cookie: name=value\r\n\r\n" >&6

while read -u7 input; do
        echo $input
done


Save that into a file called http.sh then issue forth the incantation:
$ /usr/local/bin/tcpclient www.blogger.com 80 ./http.sh || echo connection died

No comments: