Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Forced to modify perl telnet script to use both telnet and ssh

by afoken (Parson)
on Sep 01, 2012 at 17:51 UTC ( #991177=note: print w/ replies, xml ) Need Help??


in reply to Re: Forced to modify perl telnet script to use both telnet and ssh
in thread Forced to modify perl telnet script to use both telnet and ssh

ping $deviceIP or report it as not responding and exit

Just a little, slightly off-topic bean counting. Some devices prefer not to respond to pings, yet they readily serve telnet, ssh, http or other services. Yes, this is stupid behaviour, nevertheless it happens, mostly because some clueless people dictated stupid "firewall" rules.

I would omit the ping test, because it is generally useless. If you get a ping reply, you still don't know what services are supported, you only know that the device was reachable shortly after you sent the ping package. If you don't get a ping response, you know nothing. The device may be shut down, offline, firewalled, or misconfigured. In both cases, you still have to try ssh and telnet. Omitting ping reduces the amount of code needed and wastes slightly less network resources.

Another different thing: Because ssh is encrypted and telnet is not, I would prefer to connect via ssh first, and only if that fails fall back to telnet.

I would only try telnet first if I had to work with a known set of machines where telnet is much more likely enabled than ssh. But then again, if I know the machines, and know that they always respond to pings when they are up and running, a ping test may be faster then failing to establish an ssh connection.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)


Comment on Re^2: Forced to modify perl telnet script to use both telnet and ssh
Re^3: Forced to modify perl telnet script to use both telnet and ssh
by essej1 (Novice) on Sep 01, 2012 at 19:20 UTC
    Sorry I wasn't clear. We currently do have a working Perl/telnet script. Due to new security requirements we are moving to SSH. So, not all devices support SSH but will sometime in the future. Therefore I have to have a single script to handle both Telnet and SSH. (Lucky me). As stated, my dinosaur of a boss (he refuses to use new technology such as ZFS on Solaris) wants to "simply" modify the current script to handle both connections using the existing commands.

      Please go through your script adding statements like this:

      if ($device->{supportsSSH}) {SSH code} else {Telnet code}

      After a while you may notice that blocks of code keep getting repeated. Please consider refactoring them into sub {}'s as you work through your script.

Re^3: Forced to modify perl telnet script to use both telnet and ssh
by Mr. Muskrat (Abbot) on Sep 01, 2012 at 22:43 UTC

    Using ping first has become a habit for me since all of the devices we use at work respond to pings. We have a longer ssh timeout so when devices really are down, we find out sooner if we ping rather than connecting directly. (The longer timeout is due to some devices running Windows which takes longer to setup the initial ssh connection.)

    I did recommend using ssh first.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991177]
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 2014-10-25 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (141 votes), past polls