4th Floor, 4 Tabernacle Street London EC2A 4LU

Server Port Check – Net::Telnet, check remote mail server is up and online

This is pretty useful for checking that a server is accepting requests on a specific port.

In this case, i am checking port 25, but can be used for others.

./smtp_check.pl <host> <host> <host>

[perl]

use Data::Dumper;
use Net::SMTP;

my @all_emails = @ARGV;

foreach $email (@all_emails)
{
$response= check_domain($email);
print “$email ::: $response\n”;
}

sub check_domain($)
{
my $domain = shift;
use Net::Telnet;

$smtp = Net::Telnet->new(
Host=>$domain,
Port=>’25’,
Timeout => 30,
Errmode => ‘return’,
);

if ($smtp) {
# $line = $smtp->getline;
$smtp->close();
return 1;
} else {
return 0;
}
}

[/perl]