Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

Re: Perl Script to Test Telnet Connectivity

by sectokia (Pilgrim)
on Nov 09, 2022 at 02:07 UTC ( [id://11148055]=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148055]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-17 05:55 GMT
Find Nodes?
    Voting Booth?

    No recent polls found