Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Perl Script to Test Telnet Connectivity

by VinsWorldcom (Prior)
on Nov 08, 2022 at 23:58 UTC ( [id://11148053]=note: print w/replies, xml ) Need Help??


in reply to Perl Script to Test Telnet Connectivity

You're very close - as LanX points out, I think defined is what you want.

Something like this (which is not far off from what you already have):

#!perl use strict; use warnings; use Net::Telnet; sub attemptTelnetCheck { my ($host) = @_; my $t = new Net::Telnet( Errmode => 'return', Timeout => 2, Port => 1234 ); my $r = $t->open($host); if (defined $r) { $t->close(); print("$host : SUCCESS!\n"); } else { print("$host : failure. " . $t->errmsg() . "\n"); } } my @hosts = ( "192.168.10.1", "192.168.10.2" ); for my $host (@hosts) { attemptTelnetCheck($host); }
Cheers.

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

    Yes, this is fantastic! I did want defined, I just didn't know it when I was fumbling for an answer on Google. Thank you, I've fitted your code into my code, and its working perfectly. I owe you a beer!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-20 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found