7

I have question, is it possible to get header of website by using telnet? Website looks like this domain.name.server.com/~USER (just example). And I want to get it header by telnet.

telnet domain.name.server.com/~USER 80 <-- doesn't work

telnet domain.name.server.com 80 works but I neet to get ~user. Is there any possibility to do this?

19

Use telnet domain.name.server.com 80 then

HEAD /~USER HTTP/1.1
Host: domain.name.server.com

(Then you have to hit Enter once more.)

Now it should show you the header of this page.

For a real life example:

$ telnet unix.stackexchange.com 80                 
Trying 198.252.206.16...
Connected to unix.stackexchange.com.
Escape character is '^]'.
HEAD /questions/237635/using-telnet-to-get-website-header HTTP/1.1
Host: unix.stackexchange.com

HTTP/1.1 200 OK
Cache-Control: public, no-cache="Set-Cookie", max-age=60
Content-Length: 70679
Content-Type: text/html; charset=utf-8
Expires: Wed, 21 Oct 2015 19:27:43 GMT
Last-Modified: Wed, 21 Oct 2015 19:26:43 GMT
Vary: *
X-Frame-Options: SAMEORIGIN
X-Request-Guid: dbf9d0f6-0ca4-423f-98f0-4cdf2bf51bf1
Set-Cookie: prov=08886524-c640-40ad-a0ee-246db3219228; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
Date: Wed, 21 Oct 2015 19:26:43 GMT

Connection closed by foreign host.
4
  • 3
    If you don't have telnet, you can get the same sort of thing using nc or netcat (distros vary in what they call it, and there's an original and GNU version in use). Oct 21 '15 at 14:06
  • 6
    You should also include Host: unix.stackexchange.com so that the server knows which website you want, when it serves multiple sites as virtual hosts.
    – deltab
    Oct 21 '15 at 14:23
  • 2
    Why oh why are you using HTTP/1.0 here? Current (and what makes any reasonable use of the Host: header) is HTTP/1.1, the major feature of which was name-based virtual hosts.
    – user
    Oct 21 '15 at 17:54
  • If you care to help out the world just a bit, you could use TLS, too. gnutls-cli $host -p $port or openssl s_client -connect $host:$port, then type out the HTTP headers as normal. Oct 21 '15 at 20:07
2

If you can use wget instead of telnet, you can get the headers all with one command:

wget -q -S -O - domain.name.server.com/~USER | : 2>&1
  • -q turns off normal log messaging
  • -S turns on logging of headers from the server
  • -O - directs the content of the downloaded file to STDOUT
  • | : pipes the content of the downloaded file to the no-op utility :. This effectively prevents downloading the whole file, which is advantageous if it is a large file
  • 2>&1 (optional) redirects the logged headers to STDOUT

For example:

$ wget -q -S -O - unix.stackexchange.com/questions/237635/using-telnet-to-get-website-header | :
  HTTP/1.1 200 OK
  Cache-Control: public, no-cache="Set-Cookie", max-age=49
  Content-Type: text/html; charset=utf-8
  Expires: Wed, 21 Oct 2015 21:22:21 GMT
  Last-Modified: Wed, 21 Oct 2015 21:21:21 GMT
  Vary: *
  X-Frame-Options: SAMEORIGIN
  X-Request-Guid: 5ac03697-68fa-4be5-9f32-2905ec3eff38
  Set-Cookie: prov=5d9866f4-9d98-4587-a7cc-f6ea5cd76075; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
  Date: Wed, 21 Oct 2015 21:21:32 GMT
  Content-Length: 76585
$ 
1

Curl is a succinct way to view HTTP headers also:

curl -v http://unix.stackexchange.com/questions/237635/using-telnet-to-get-website-header
1
  • 3
    Welcome (?) to Unix & Linux!  You have posted the above as an answer, but it does not really answer the question (“is it possible to get the header of a website by using telnet?”).  Helpful hints should be done in comments, for which you need a little more reputation. Oct 21 '15 at 22:20
-1

You can also do this over https, using openssl instead of telnet. There is an example in this tutorial that I recently published:

openssl s_client -connect domain.name.server.com:443
HEAD /~USER HTTP/1.0
Host: domain.name.server
4
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Sep 9 '17 at 14:50
  • 1
    @SatōKatsura Well, technically, “You can also do this over https, using openssh instead of telnet” does look like an attempt at an answer. But it's completely wrong: ssh has nothing to do with https, and anyway an http website would not respond over https. Sep 9 '17 at 14:54
  • Yes, but the answer becomes correct with openssl instead of openssh, which is what the linked tutorial says (provided, of course, the site also supports https). It could be a honest typo... Sep 9 '17 at 15:29
  • The (currently most recent) comment by Blacklight Shining on the answer unix.stackexchange.com/a/237648/100397 offers a solution using OpenSSL.- openssl s_client -connect $host:$port. I've added that in here, since it's pretty much what the YouTube video does, but more d r a w n - o u t.
    – roaima
    Sep 9 '17 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.