System(ping)

Hi,

any idea how I can hand over each object of the array ip_list to the
system(ping) ?

Here the code:
ip_list = [‘192.168.1.1’ , ‘192.168.1.2’ , ‘192.168.1.3’ , ‘192.168.1.4’
, ‘192.168.1.5’ , ‘192.168.1.6’ , ‘192.168.1.7’ ]

ip_list.each do |host|
system(‘ping -c 5’ + host)
end

bye
Henry

Iñaki Baz C. wrote:

El Jueves, 17 de Abril de 2008, Heinrich P. escribió:

    system('ping -c 5' + host)

end

use Ping class:

require ‘ping’

ip_list.each do { |ip| Ping.pingecho(ip, 3) }

This Class does not support ICMP pings.

bye
Henry

El Jueves, 17 de Abril de 2008, Heinrich P. escribió:

    system('ping -c 5' + host)

end

use Ping class:

require ‘ping’

ip_list.each do { |ip| Ping.pingecho(ip, 3) }

El Jueves, 17 de Abril de 2008, Heinrich P. escribió:

This Class does not support ICMP pings.

Sorry, you are rigtht. It just does a TCP syn.

Hi,

From: “Heinrich P.” [email protected]

Iñaki Baz C. wrote:

require ‘ping’

ip_list.each do { |ip| Ping.pingecho(ip, 3) }

This Class does not support ICMP pings.

For what it’s worth, here’s a traceroute in ruby that uses ICMP:

http://code.google.com/p/rubyroute/

(The program is very short, so I’ve attached it to this email.)

Regards,

Bill

From: Heinrich P. [mailto:[email protected]]

ip_list = [‘192.168.1.1’ , ‘192.168.1.2’ , ‘192.168.1.3’ ,

‘192.168.1.4’

, ‘192.168.1.5’ , ‘192.168.1.6’ , ‘192.168.1.7’ ]

ip_list.each do |host|

system(‘ping -c 5’ + host)

replace that with

      system('ping', '-c 5', host)

or
system(“ping -c 5 #{host}”)

end

kind regards -botp

On Thu, 17 Apr 2008 16:04:39 -0500, Heinrich P. wrote:

    system('ping -c 5' + host)

end

I think you’re missing a space after the 5.

On Apr 17, 3:04 pm, Heinrich P. [email protected] wrote:

    system('ping -c 5' + host)

end

gem install net-ping

Regards,

Dan

On Sat, Apr 19, 2008 at 12:40 AM, Ken B. [email protected] wrote:

ip_list.each do |host|
system(‘ping -c 5’ + host)
end

I think you’re missing a space after the 5.

Good eyes!

Arlen

Daniel B. wrote:

On Apr 17, 3:04�pm, Heinrich P. [email protected] wrote:

� � � � system(‘ping -c 5’ + host)
end

gem install net-ping

Regards,

Dan

Hi all,

thanks for your input.
Here the script which checks packet loss and sends me an e-mail:

#!/usr/bin/ruby

require “net/ping”
include Net
require ‘socket’
include Socket::Constants
require ‘daemons’
include Daemonize
require ‘action_mailer’

all for mailing requirementsActionMailer::Base.sendmail_settings = {

:address => ‘mailhostXYZ’,
ActionMailer::Base.sendmail_settings = { :address => ‘mailhostXYZ’,
:port
=> 25 }
@RecipientAddress = ‘[email protected]

class SimpleMailer < ActionMailer::Base
def simple_message(recipient)
from ‘[email protected]
recipients recipient
subject ‘Packet loss detected’
body $Message
end
end

daemonize()

ip_list = [ ‘192.168.1.1’ , ‘192.168.1.2’ , ‘192.168.1.3’ ,
‘192.168.1.4’ , ‘192.168.1.5’ , ‘192.168.1.6’ , ‘192.168.1.7’ ,
‘192.168.1.8’ ]
#total_networks_to_check = ip_list.size
#puts ip_list.size

loop do
begin
amount_of_pings = 10

PingTCP.econnrefused = true

ip_list.each_with_index do |item, index|

counter_positive = 0
counter_negative = 10

10.times do
pe = Net::PingExternal.new(“#{item}”)

if pe.ping
#puts “External ping successful”
counter_positive = counter_positive + 1
#puts 'counter_positive ’ + counter_positive.to_s
else
counter_negative = counter_negative - 1
#puts 'counter_negative ’ + counter_negative.to_s
end
end
#if counter_negative > 0
success_rate = (100 * counter_positive) /
amount_of_pings
#puts 'success_rate = ’ + success_rate.to_s
packet_loss = 100 - success_rate
if packet_loss > 0
$Message = packet_loss.to_s + '% packet loss
for ’ + “#{item}”
SimpleMailer.deliver_simple_message(@RecipientAddress)
#puts 'packet_loss = ’ + packet_loss.to_s
else
success_rate = 0
end
#end
end
end
sleep 60
end

I had to delete some sensitive data, but this should basically work for
everyone.

bye
Henry

Andrew D. wrote:

I have tried to use this script that you posted but keep getting the
same error over and over:

uninitialized constant PingTCP (NameError)

I have searched gems, and tried to reword this but nothing works, what
do I do?!

Try Ping::TCP.

Regards,

Dan

I have tried to use this script that you posted but keep getting the
same error over and over:

uninitialized constant PingTCP (NameError)

I have searched gems, and tried to reword this but nothing works, what
do I do?!

Andrew

Daniel B. wrote:

Try Ping::TCP.

Regards,

Dan

Cheers, that fixed that problem but I get the error that I think that
line is meant to prevent showing or happening:

Connection refused - connect(2) (Errno::ECONNREFUSED)

Andrew D. wrote:

Daniel B. wrote:

Try Ping::TCP.

Regards,

Dan

Cheers, that fixed that problem but I get the error that I think that
line is meant to prevent showing or happening:

Connection refused - connect(2) (Errno::ECONNREFUSED)

Sorry everyone, this was my fault, I setup ActionMailer to use sendmail
not SMTP!!

Regards,
Andrew

I have hit another problem now, I have moved this app over to a windows
server, and installed all the needed gems, but the app never seems to be
able to ping the ip addresses I have put in the file, but it all works
under linux and unix?

I have even tried installing the “windows versions” of the gems and no
luck.

Is there something that I am missing?