port check with perl

If you are on a machine without telnet you can use this perl script to check connectivity.

#!/usr/bin/perl

# nettest.pl
#

use IO::Socket;
use Errno;
$| = 1;

$host = shift;
$port = shift;
$type = shift || “tcp”;
die “No Host parameter!” if !$host;
die “No Port parameter!” if !$port;

my $rc = new IO::Socket::INET
PeerAddr => $host,
PeerPort => $port,
Proto => $type,
Timeout => 5 or die “\nCan’t bind : $@\n”;

print “\nSuccessfully bound to $host on port $port\n”;

This entry was posted in Uncategorized. Bookmark the permalink.