in reply to Perl Script to Test Telnet Connectivity

This will do what you have requested: Connect via TCP and receive the first message sent form the server (which is the 'SSH-2.0-OpenSSH_7.4' you are after):

use IO::Socket::INET; # Connect to TCP socket my $socket = new IO::Socket::INET( PeerHost => '', PeerPort => '1234', Proto => 'tcp', Timeout => 3 ); if ($socket) { # We are connected... my $buffer = ""; my $length = 1024; $socket->recv($buffer, $length); $socket->close(); print "OK - got message '$buffer'"; } else { # Connection failed print "Failed"; }

Replies are listed 'Best First'.
Re^2: Perl Script to Test Telnet Connectivity
by redapplesonly (Sexton) on Nov 09, 2022 at 18:20 UTC

    This looks great, thank you! I was tempted to use from-scratch socket programming, but didn't know how to start...

      I'd like to add that the TCP method is better anyway. SSH doesn't actually talk a telnet-compatible protocol, it just happens to show you something useful when you connect with a standard telnet client. You shouldn't rely on it being compatible with a module that expects an actual telnet server on the other end.