Skip to main content

Command Palette

Search for a command to run...

Using bash redirection to fetch a website

Updated
•1 min read•View as Markdown
Using bash redirection to fetch a website

Now this is something very cool. We are going to fetch a website using a special file in linux that represents a network connection. These are in the form /dev/protocol/host/port.

What we are going to do is to open up a tcp connection at www.slackware.com:80. Port 80 is the default port of HTTP.

Like this

$ exec 3<>/dev/tcp/www.slackware.com/80

Here we have opened up this special file representing the tcp connection for both reading and writing and assigned file descriptor 3.

Next step is to send a GET request.

$ echo $'GET /info/ HTTP/1.1\r\nHost: www.slackware.com\r\nConnection: close\r\n\r\n' >&3

Notice how the request is sent to file descriptor 3 linked to the special file, which is our representation of the network connection.

Finally, we retrieve the response and feed the html dump to the lynx browser.

$ lynx -stdin <&3

Note how the response is also fetched from the special file via file descriptor 3.

Hopefully you will see lynx browser open up with the page from www.slackware.com. Notice that the page fetched is from www.slackware.com/info in this case, because of how the GET request is constructed.

More from this blog

Linux and Web

31 posts