Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Perl Script to Test Telnet Connectivity

by sectokia (Monk)
on Nov 09, 2022 at 02:07 UTC ( #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 => '10.0.0.1', 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2023-02-03 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (26 votes). Check out past polls.

    Notices?