Perl Cookbook

Perl CookbookSearch this book
Previous: 17.18. Program: fwdportChapter 18Next: 18.1. Simple DNS Lookups
 

18. Internet Services

Contents:
Introduction
Simple DNS Lookups
Being an FTP Client
Sending Mail
Reading and Posting Usenet News Messages
Reading Mail with POP3
Simulating Telnet from a Program
Pinging a Machine
Using Whois to Retrieve Information from the InterNIC
Program: expn and vrfy

This "telephone" has too many shortcomings to be seriously considered as a means of communication. The device is inherently of no value to us.

-  - Western Union internal memo, 1876

18.0. Introduction

Correct use of sockets is only part of network communicating programs. Once you have a way for two programs to talk, you still need a protocol for communication. This protocol lets each party know when to talk, and it precisely defines who is responsible for which part of the service.

Common Internet protocols are:

Protocol

Meaning

Action

FTP

File Transfer Protocol

Copying files between remote machines

telnet

Remote login

rsh and rcp

Remote shell and Remote copy

Remote login and remote file copying

NNTP

Network News

Transfer Protocol

Reading and posting USENET news

HTTP

Hypertext Transfer Protocol

Transferring documents on the Web

SMTP

Simple Mail Transfer Protocol

Sending mail

POP3

Post Office Protocol

Reading mail

Even something as relatively simple as connecting to a remote computer requires intricate negotiations between client and server and has numerous dynamically configurable options. If you had to write the Perl code to implement these protocols each time you wanted to use a network service, you'd probably end up writing a lot of buggy programs, try to get demoted into a management position, or both.

Fortunately, CPAN has modules for these protocols. Most modules implement the client side of the protocol rather than the server side. This means your program can use these modules to send mail, but not to be a mail server that other clients connect to; to read and post news, but not be a news server that other clients connect to; to transfer files to and from an FTP server, but not to be an FTP server that other clients connect to; and so on.

Most of these modules fall under the Net:: hierarchy. We'll be using Net::FTP to send and receive files using FTP, Net::NNTP to read and post Usenet news, Net::Telnet to simulate a connection to another machine, Net::Whois to find out information about a domain name, Net::Ping to check whether a machine is alive, and Net::POP3 and Mail::Mailer to receive and send mail. We deal with the CGI protocol in Chapter 19, CGI Programming, and HTTP in Chapter 20, Web Automation.

You can thank Graham Barr for most of these modules, whose IO::Socket modules we used for low-level network communication in Chapter 17, Sockets. He wrote Net::FTP, Net::NNTP, Net::POP3, and Mail::Mailer. Jay Rogers wrote Net::Telnet, and Chip Salzenberg wrote Net::Whois. Thank these folks that you don't have to reinvent these tricky wheels!


Previous: 17.18. Program: fwdportPerl CookbookNext: 18.1. Simple DNS Lookups
17.18. Program: fwdportBook Index18.1. Simple DNS Lookups

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.