http://www.perlmonks.org?node_id=991177


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

Replies are listed 'Best First'.
Re^3: Forced to modify perl telnet script to use both telnet and ssh
by Mr. Muskrat (Canon) 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.

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.