Port Monitor

Most TCP/IP services use static ports to listen for incoming requests. Monitoring these ports allows you to see whether particular servers or services are responding or not. For example, you can tell whether your mail server is alive by periodically poking port 25, which is the port on which an SMTP server listens for requests. Some other ports to monitor are FTP (23), HTTP (80) and POP3 (110).[68] A freely available program called netcat can connect to and interact with a specific port on any device. We can write a wrapper for this program to watch a given port or service; if something happens outside of its normal operation, then we can send a trap. In this section, we’ll develop a wrapper that checks the SMTP port (25) on our mail server. The program is very simple, but the results are outstanding!

Before we start to write the program, let’s establish what we want to do. Telnet to port 25 of your SMTP server. Once you’re connected, you can issue the command HELO mydomain.com. This should give you a response of 250. After you get a response from the mail server, issue the QUIT command, which tells the server you are done. Your session should look something like this:

$ telnet mail.ora.com 25
220 smtp.oreilly.com ESMTP O'Reilly & Associates Sendmail 8.11.2 ready
HELO mydomain.com
250 OK
QUIT
221 closing connection

The netcat program needs to know what commands you want to send to the port you are monitoring. We will be sending only two commands to our mail server, ...

Get Essential SNMP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.