How does one browse a website using Telnet?

9

4

When you connect to an open port 80 (HTTP) through Telnet, shouldn't the client display a plaintext version of the site? All I get is a blank screen, and then the client disconnects. I know you can use lynx to browse the web in a command-line interface, but I'd like to know why Telnet can't do the exact same thing. Thank you very much!

SolidSnake859

Posted 2015-06-27T01:53:18.077

Reputation: 242

2Unfair comparison. Lynx is a web browser; it communicates using HTTP to the web server. Telnet is a plain-text shell (command-line interface), and typically uses TCP. Apples versus oranges; the telnet client cannot communicate with the HTTP web server, and vice-versa due to incompatible IPs. – sawdust – 2015-06-27T02:24:34.547

1Lynx uses the HTTP protocol which is laid on top of TCP/IP (protocol for the communication/data transfer), telnet provides the means to use TCP/IP. When using telnet in this way YOU must provide the basics of the HTTP protocol in the same way as Lynx. – Hannu – 2015-06-27T08:09:43.000

Answers

8

When you use Telnet, you're opening an almost raw TCP connection to the server. This means that you have to make HTTP requests like your browser does to get the information that you need.

Try this:

> telnet google.com 80

You should get an empty window with a blinking cursor at the top. Now type this in:

GET / HTTP/1.1

and press Enter twice to send the line and end the request with an empty line. You won't be able to see what you're typing, though, because the server is not echoing back what you're typing (but the Telnet client moves the cursor for you).

You should get your response in HTML. Extra points if you can save it to a file and open it in a browser.

So then, what's Lynx? Lynx does exactly what your browser does: send requests, get the response, parse the HTML, and show it to the user. But this is all done in a command-line interface, which makes it difficult to align objects and format them correctly.

Telnet, on the other hand, just handles the requesting and responding part, which is why only crazy people browse the Web with just Telnet.

oldmud0

Posted 2015-06-27T01:53:18.077

Reputation: 3 858

Wow. Thank you all for your helpful comments! I'm going to try what oldmud0 suggested...because I'm one of those crazy people. – SolidSnake859 – 2015-06-27T10:14:52.243

Man, that was an ordeal. But I got it! First, I used the -f argument to save the session as a text file: [telnet -f C:\Downloads\telsesh.txt www.google.com 80]. Then I realized that the raw html didn't format properly in notepad, so I downloaded Notepad++, installed its TextFX plugin, selected [TextFX>TextFX Edit>Reindent C++ Code], saved the file as html, and ran it in Google Chrome (CTRL+ALT+SHIFT+R). Worth it. – SolidSnake859 – 2015-06-27T11:17:58.960

1I never say this, but: thanks to this answer, I've finally passed 1000 rep! Woo! – oldmud0 – 2015-06-27T13:39:45.800

1@SolidSnake859 As an aside, if your intentions are merely to download a webpage via the command line, wget is more ideal. Usage is simple: wget <url>. Regarding the formatting in Notepad, Google minimizes their homepage by removing unnecessary formatting. HTML tidy is an alternative solution. Also note that notepad chokes on Linux linebreaks (last I saw). – Kat – 2015-07-02T19:25:30.990

1@Mike or cURL while you're at it – oldmud0 – 2015-07-02T22:39:36.763

If the site is using shared hosting, as many websites do, you also need to send a Host: google.com header. Otherwise it won't know which virtual host you want to access. – Barmar – 2015-07-04T05:13:59.277