11

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!

2
  • 2
    Unfair 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
    Commented Jun 27, 2015 at 2:24
  • 1
    Lynx 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
    Commented Jun 27, 2015 at 8:09

1 Answer 1

13

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.

6
  • Wow. Thank you all for your helpful comments! I'm going to try what oldmud0 suggested...because I'm one of those crazy people.
    – user463277
    Commented Jun 27, 2015 at 10:14
  • 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.
    – user463277
    Commented Jun 27, 2015 at 11:17
  • 1
    I never say this, but: thanks to this answer, I've finally passed 1000 rep! Woo!
    – oldmud0
    Commented Jun 27, 2015 at 13:39
  • 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
    Commented Jul 2, 2015 at 19:25
  • 1
    @Mike or cURL while you're at it
    – oldmud0
    Commented Jul 2, 2015 at 22:39

You must log in to answer this question.