Just needed to get to know whether something listens at a certain TCP port on a particular host.

Here is my workaround using Perl:

my $sock = IO::Socket::INET->new (
	PeerAddr => "",
	PeerPort => 1337,
	Proto => "tcp",
	Timeout => 1
echo "closed" if !defined $sock;

Works at least for me. Any concerns or better solutions?

Martin Scharm

stuff. just for the records.

1 Comment

rocky | Permalink | 2013-11-09 19:07:27

Two alternatives come to mind. First use telnet with a port number. For example (using values in your example):

telnet 1337

You’ll have to know how to close the connection if there is a “Connected” message.

Second use nmap which is something sysadmins should get very familiar with. Here:

nmap -p 1337

Post a comment

read more about submitting comments