How to Talk to TCP Ports

It's easy to forget how to telnet to a port and talk to a daemon.

HTTP

Note that the 404 response for the authenticated example is because I deliberated specified a URL that doesn't exist.

HTTP 1.1 - Without authentication

# telnet maxx.shmoo.com 80 
Trying 205.134.188.171...
Connected to maxx.shmoo.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: adam.shand.net

HTTP/1.1 200 OK
Date: Wed, 18 Mar 2009 22:02:05 GMT
Server: Apache/2.2.9 (Debian) DAV/2 PHP/5.2.6-1+lenny2 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g
Last-Modified: Sun, 20 Jul 2008 08:06:39 GMT
ETag: "2a810d8-131a-45270120561c0"
Accept-Ranges: bytes
Content-Length: 4890
Content-Type: text/html; charset=UTF-8

HTTP 1.1 - With failed authentication

misfire(shand)$ telnet maxx.shmoo.com 80 
Trying 67.207.134.156...
Connected to maxx.shmoo.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: maxx.shmoo.com
Authorization: Basic YWRhbTpzZWNyZXQK=

HTTP/1.1 401 Authorization Required
Date: Wed, 18 Mar 2009 22:03:52 GMT
Server: Apache/2.2.8 (Debian) PHP/5.2.5-3 with Suhosin-Patch
WWW-Authenticate: Basic realm="maxx.shmoo.com"
Content-Length: 516
Content-Type: text/html; charset=iso-8859-1

HTTP 1.1 - With successful authentication

# telnet maxx.shmoo.com 80 
Trying 192.168.17.179...
Connected to maxx.shmoo.com.
Escape character is '^]'.
GET /nothere HTTP/1.1 
Host: maxx.shmoo.com
Authorization: Basic YWRhbTpzZWNyZXQK=

HTTP/1.1 404 Not Found
Date: Wed, 18 Mar 2009 22:07:53 GMT
Server: Apache/1.3.34 (Debian) mod_perl/1.29 DAV/1.0.3 PHP/5.2.0-8+etch11
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1

IMAP

Need to remember details of how to actual list, retrieve and delete messages.

# telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK dovecot ready.
AA CAPABILITY
* CAPABILITY IMAP4rev1 SORT THREAD=REFERENCES MULTIAPPEND UNSELECT LITERAL+ IDLE CHILDREN LISTEXT LIST-SUBSCRIBED STARTTLS AUTH=PLAIN
AA OK Capability completed.
AD LOGIN adam secret
AD OK Logged in.
a4 LIST "" *
* LIST (\HasChildren) "." INBOX
* LIST (\HasNoChildren) "." "Foo"
* LIST (\HasChildren) "." "Bar"
a5 SELECT Foo
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 194 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1047965829] UIDs valid
* OK [UIDNEXT 272] Predicted next UID
a5 OK [READ-WRITE] Select completed.
AE logout
* BYE Logging out
AE OK Logout completed.
Connection closed by foreign host.

NNTP

# telnet localhost 119
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
200 news NNTPCache server V3.0.1 [see www.nntpcache.org]  (c) 1996-2002 Julian Assange <proff@iq.org> May 27 2004 ready (posting ok, 72154 groups available).
215
24hoursupport.helpdesk 730507 600741 y
...<snip>...
gmane.comp.java.dna.devel 15 1 m
.
listgroup gmane.comp.java.dna.devel         
211 Article list follows
1
...<snip>...
15
.
GROUP gmane.comp.java.dna.devel
211 15 1 15 gmane.comp.java.dna.devel
article 12
220 12 <c76j3b$neq$1@sea.gmane.org> article
Path: main.gmane.org!not-for-mail
From: Mauro Talevi <mauro.talevi-hQ+s5KbX5YmGglJvpFV4uA@public.gmane.org>
Newsgroups: gmane.comp.java.dna.devel
Subject: Re: Release 1.1
Date: Tue, 04 May 2004 00:09:13 +0100
Lines: 10
...<snip>...
.
quit
205
Connection closed by foreign host.

POP3

# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK dovecot ready.
user adam
+OK
pass secret
+OK Logged in.
list
+OK scan listing follows
1 2667
2 2763
...<snip> ...
1120 2490
1121 122715
1122 2750
.
retr 1120
+OK 2490 octets
Return-Path: <support@...>
X-Original-To: adam@...
Delivered-To: adam@...
Received: from flexo.sydneywireless.com (flexo.sydneywireless.com [202.93.176.34])
        by ronin.spack.org (Postfix) with ESMTP id E257C2C103
        for <adam@...>; Sun, 13 Jun 2004 16:54:12 -0700 (PDT)
Received: (qmail 1173 invoked by uid 0); 13 Jun 2004 23:54:04 -0000
Date: 13 Jun 2004 23:54:04 -0000
Message-ID: <20040613235404.1172.qmail@flexo.sydneywireless.com>
To: adam@...
Subject: Your new certificate for ssl.spack.org
From: support@...

-----BEGIN CERTIFICATE-----
MIIFRDCCAyygAwIBAgIDAJG5MA0GCSqGSIb3DQEBBAUAMHkxEDAOBgNVBAoTB1Jv
...<snip> ...
5o4Wey39C/U=
-----END CERTIFICATE-----
.
dele 1120
+OK Marked to be deleted.
quit
+OK Logging out, messages deleted.
Connection closed by foreign host.

SMTP

SMTP without authentication

# telnet localhost 25 
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 ronin.spack.org ESMTP We own your foo.
ehlo ronin.spack.org
250-ronin.spack.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-XVERP
250 8BITMIME
MAIL FROM: adam@domain.com
250 Ok
RCPT TO: adam@otherdomain.com
250 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: there must be a blank line between the end of the headers and the start of the message body

this is the message body, type a period on a line by itself to end the message body.
.
250 Ok: queued as 9AA8D2C125
quit
221 Bye
Connection closed by foreign host.

SMTP with STARTLS and SMTPAUTH

ronin(adam)$ swaks -tls -a
To: adam@shand...
Username: adam
Password: <snip>
=== Trying ronin.spack.org:25...
Connected to ronin.spack.org.
<-  220 ronin.spack.org ESMTP "Sarge is once again proof that communities can do great things even communities of irritable, cantankerous, grudge-holding, flaming Free Software nuts. ;)" -- Steve Langasek
 -> EHLO ronin
<-  250-ronin.spack.org
<-  250-PIPELINING
<-  250-SIZE 10240000
<-  250-VRFY
<-  250-ETRN
<-  250-STARTTLS
<-  250 8BITMIME
 -> STARTTLS
<-  220 Ready to start TLS
=== TLS started w/ cipher DHE-RSA-AES256-SHA
 ~> EHLO ronin
<~  250-ronin.spack.org
<~  250-PIPELINING
<~  250-SIZE 10240000
<~  250-VRFY
<~  250-ETRN
<~  250-AUTH LOGIN PLAIN
<~  250-AUTH=LOGIN PLAIN
<~  250 8BITMIME
 ~> AUTH PLAIN GAF<snip>cH1=
<~  235 Authentication successful
 ~> MAIL FROM:<adam@ronin>
<~  250 Ok
 ~> RCPT TO:<adam@shand...>
<~  250 Ok
 ~> DATA
<~  354 End data with <CR><LF>.<CR><LF>
 ~> Date: Mon, 28 Aug 2006 12:09:46 -0700
 ~> To: adam@shand...
 ~> From: adam@ronin
 ~> Subject: test Mon, 28 Aug 2006 12:09:46 -0700
 ~> X-Mailer: swaks v20040404.1 jetmore.org/john/code/#swaks
 ~> 
 ~> This is a test mailing
 ~> 
 ~> .
<~  250 Ok: queued as D42102ACA3
 ~> QUIT
<~  221 Bye

2014 by adam shand. sharing is an act of love, please share.