Check TCP Port 80 (http) with telnet

From Thomas-Krenn-Wiki
Jump to: navigation, search

In this article, we will show you how you can test accessing a web server through TCP port 80 using telnet.

HTTP Protocol Basics

HTTP[1] is a plaintext protocol. Thereby, simulating a browser and testing access through port 80 using the telnet command becomes simple.

The following steps are necessary for this from a Linux command line:

  1. Execute telnet SERVERNAME 80. Thereby, telnet will connect to the server named SERVERNAME through port 80.
  2. If the establishment of the TCP connection is possible, telnet will respond with the messages: Connected to SERVERNAME. and Escape character is '^]'.
  3. A web page can now be requested using the HTTP protocol (such as the server’s web site). Enter the following two lines to do this and press afterwards the Enter key two times:
    GET / HTTP/1.1
    HOST: HOSTNAME
  4. The server will respond with the HTTP status and the web page (such as HTTP/1.1 200 OK and so forth.)

Example

In the following example, the http://checkip.dyndns.org/[2] page will be accessed. The following commands will be entered on the Linux command line, followed by pressing the Enter two times:

telnet checkip.dyndns.org 80
GET / HTTP/1.1
HOST: checkip.dyndns.org

The checkip.dyndns.org server will respond with HTTP Response, which will also contain the HTML code for the web page:

[user@fedora9 user]$ telnet checkip.dyndns.org 80
Trying 204.13.249.70...
Connected to checkip.dyndns.org.
Escape character is '^]'.
GET / HTTP/1.1
HOST: checkip.dyndns.org

HTTP/1.1 200 OK
Content-Type: text/html
Server: DynDNS-CheckIP/1.0
Connection: close
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 106

<html><head><title>Current IP Check</title></head><body>Current IP Address: 91.113.127.247</body></html>
Connection closed by foreign host.
[user@fedora9 user]$ 

Change Escape Character

If necessary, you can change the escape character when you call telnet:

[user@fedora9 user]$ telnet checkip.dyndns.org 80 -e+

This call uses -e to define a plus sign as an escape character.

References

  1. Hypertext Transfer Protocol (en.wikipedia.org)
  2. For details, see http://www.dyndns.com/support/tools/


Foto Werner Fischer.jpg

Author: Werner Fischer

Werner Fischer, working in the Web Operations & Knowledge Transfer team at Thomas-Krenn, completed his studies of Computer and Media Security at FH Hagenberg in Austria. He is a regular speaker at many conferences like LinuxTag, OSMC, OSDC, LinuxCon, and author for various IT magazines. In his spare time he enjoys playing the piano and training for a good result at the annual Linz marathon relay.


Related articles

DRBD
HA Cluster with Linux Containers based on Heartbeat, Pacemaker, DRBD and LXC
Restoring a Clonzilla Image