9.2 Investigating Protocols with Telnet
In this chapter,
you'll see clients that use sockets to communicate
with a number of well-known Internet services such as HTTP, echo, and
more. The sockets themselves are simple enough; however, the
protocols to communicate with different servers make life complex.To get a feel for how a protocol operates, you can use
Telnet to connect to
a server, type different commands to it, and watch its responses. By
default, Telnet attempts to connect to port 23. To connect to servers
on different ports, specify the port you want to connect to like
this:
% telnet localhost 25
|
machine; SMTP is the protocol used to transfer email between servers
or between a mail client and a server. If you know the commands to
interact with an SMTP server, you can send email without going
through a mail program. This trick can be used to forge email. For
example, a few years ago, the summer students at the National Solar
Observatory in Sunspot, New Mexico, made it appear that the party one
of the scientists was throwing after the annual volleyball match
between the staff and the students was in fact a victory party for
the students. (Of course, the author of this book had absolutely
nothing to do with such despicable behavior. ;-) ) The interaction
with the SMTP server went something like this; input the user types
is shown in bold (the names have been changed to protect the
gullible):
flare% telnet localhost 25Several members of the staff asked Bart why he, a staff member, was
Trying 127.0.0.1 ...
Connected to localhost.sunspot.noao.edu.
Escape character is '^]'.
220 flare.sunspot.noao.edu Sendmail 4.1/SMI-4.1 ready at
Fri, 5 Jul 93 13:13:01 MDT
HELO sunspot.noao.edu
250 flare.sunspot.noao.edu Hello localhost [127.0.0.1], pleased to meet you
MAIL FROM: bart
250 bart... Sender ok
RCPT TO: local@sunspot.noao.edu
250 local@sunspot.noao.edu... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
In a pitiful attempt to reingratiate myself with the students
after their inevitable defeat of the staff on the volleyball
court at 4:00 P.M., July 24, I will be throwing a victory
party for the students at my house that evening at 7:00.
Everyone is invited.
Beer and Ben-Gay will be provided so the staff may drown
their sorrows and assuage their aching muscles after their
public humiliation.
Sincerely,
Bart
.
250 Mail accepted
QUIT
221 flare.sunspot.noao.edu delivering mail
Connection closed by foreign host.
throwing a victory party for the students. The moral of this story is
that you should never trust email, especially patently ridiculous
email like this, without independent verification. The other moral of
this story is that you can use Telnet to simulate a client, see how
the client and the server interact, and thus learn what your Java
program needs to do. Although this session doesn't
demonstrate all the features of the SMTP protocol,
it's sufficient to enable you to deduce how a simple
email client talks to a server.
• Table of Contents• Index• Reviews• Reader Reviews• Errata• AcademicJava Network Programming, 3rd EditionBy
Elliotte Rusty Harold Publisher: O'ReillyPub Date: October 2004ISBN: 0-596-00721-3Pages: 706
Thoroughly revised to cover all the 100+ significant updates
to Java Developers Kit (JDK) 1.5, Java Network
Programming is a complete introduction to
developing network programs (both applets and applications)
using Java, covering everything from networking fundamentals
to remote method invocation (RMI). It includes chapters on
TCP and UDP sockets, multicasting protocol and content
handlers, servlets, and the new I/O API. This is the
essential resource for any serious Java developer.
