hxbsy has asked for the wisdom of the Perl Monks concerning the following question:

ping 192.168.63.121
PING 192.168.63.121: 56 data bytes, press CTRL_C to break
Reply from 192.168.63.121: bytes=56 Sequence=1 ttl=60 time=4 ms
Reply from 192.168.63.121: bytes=56 Sequence=2 ttl=60 time=14 ms
Reply from 192.168.63.121: bytes=56 Sequence=3 ttl=60 time=1 ms
Reply from 192.168.63.121: bytes=56 Sequence=4 ttl=60 time=2 ms
Reply from 192.168.63.121: bytes=56 Sequence=5 ttl=60 time=1 ms

--- 192.168.63.121 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 1/4/14 ms

<h3c>

Can I get the "0.00% packet loss"? I want to know peer ip is alive or not.
now my code as following:

$consoleprompt = 'yes\/no|assword|[\$#>\]]$|[\$#>\]] $|>.$|].$'; $ssh->send("ping $ip"); $ssh->waitfor($consoleprompt,5); $prematch=$ssh->before(); $ssh->waitfor($consoleprompt,5);

Replies are listed 'Best First'.
Re: How to use "$ssh->before()"
by vinoth.ree (Monsignor) on Apr 15, 2015 at 11:10 UTC
    I want to know peer ip is alive or not.

    If you know the peer IP addresses, use Net::Ping module to ping set of IP addresses,

    Ex,

    use Net::Ping; my $p = Net::Ping->new("icmp"); my @host_array = (IP1,IP2,IP3...); foreach $host (@host_array) { print "$host is "; print "NOT " unless $p->ping($host, 2); print "reachable.\n"; sleep(1); } $p->close();

    All is well. I learn by answering your questions...

      or, alternately (because using icmp may require addtl info)...

      #! /usr/bin/perl -w use 5.018; # cf [id://1123481] -> my $p = Net::Ping->new("icmp"); # method not allowed by (some) hosts, YMMV! my @host_array = ('n+.n+.n+.n+', 'n+.n+.n+.n+', .... ); say "\n Pinging so-and-so(s)\n"; use Net::Ping; my $p = Net::Ping->new("syn"); for my $host (@host_array) { if ($p->ping($host) ) { say "Host $host is alive \n (at least, 'arguably' See doc re +'syn' protocol)\n"; } else { say "Could not ping host $host, $!"; } $p->close(); }
Re: How to use "$ssh->before()"
by ww (Archbishop) on Apr 15, 2015 at 10:42 UTC

    If the data shown is the product of your complete script (and since you didn't post your complete script, we can't tell) then your question needs clarification.

    Please read the documentation for whatever vers. of SSH 1 you're using... and perhaps read about ping as well, because "0.00% packet loss" means the server on the ip you pinged IS alive -- you got responses. Ditto the match between the numbers of packets transmitted and received.

    Update: 1 Kudos to Prior vinoth.ree appears to have identified the most likely SSH module supporting $prematch.... ++.



    If you didn't read the docs, shame!

      He is using Net::SSH::Expect, Of course it took time for me to find which module gives these methods.


      All is well. I learn by answering your questions...

      Thx
      The data shown on the H3C switch.actually I want to check the peer IP of swith port is alive or not,so i can be notified that the connected line is up or down.
      I prefer Net::SSH module.but i don't know how to use "$ssh->before()",when the perl script logins to the switch.