system(ping)

H

Heinrich Piard

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

Iñaki Baz Castillo

El Jueves, 17 de Abril de 2008, Heinrich Piard escribi=C3=B3:
Hi,

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

Here the code:
ip_list =3D ['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


use Ping class:

require 'ping'

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

=2D-=20
I=C3=B1aki Baz Castillo
 
H

Heinrich Piard

Iñaki Baz Castillo said:
El Jueves, 17 de Abril de 2008, Heinrich Piard escribió:


use Ping class:

require 'ping'

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

This Class does not support ICMP pings.


bye
Henry
 
I

Iñaki Baz Castillo

El Jueves, 17 de Abril de 2008, Heinrich Piard escribi=C3=B3:
This Class does not support ICMP pings.

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


=2D-=20
I=C3=B1aki Baz Castillo
 
P

Peña, Botp

RnJvbTogSGVpbnJpY2ggUGlhcmQgW21haWx0bzpsaW51eEBwaWFyZC5kZV0gDQojIGlwX2xpc3Qg
PSBbJzE5Mi4xNjguMS4xJyAsICcxOTIuMTY4LjEuMicgLCAnMTkyLjE2OC4xLjMnICwgDQojICcx
OTIuMTY4LjEuNCcNCiMgLCAnMTkyLjE2OC4xLjUnICwgJzE5Mi4xNjguMS42JyAsICcxOTIuMTY4
LjEuNycgXQ0KIyANCiMgaXBfbGlzdC5lYWNoIGRvIHxob3N0fA0KIyAgICAgICAgIHN5c3RlbSgn
cGluZyAtYyA1JyArIGhvc3QpDQoNCnJlcGxhY2UgdGhhdCB3aXRoDQoNCiAgICAgICAgICBzeXN0
ZW0oJ3BpbmcnLCAnLWMgNScsIGhvc3QpDQoNCm9yDQogICAgICAgICAgc3lzdGVtKCJwaW5nIC1j
IDUgI3tob3N0fSIpDQoNCiMgZW5kDQojDQoNCg0Ka2luZCByZWdhcmRzIC1ib3RwDQo=
 
K

Ken Bloom

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

I think you're missing a space after the 5.
 
D

Daniel Berger

Hi,

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

Here the code:
ip_list =3D ['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|
=A0 =A0 =A0 =A0 system('ping -c 5' + host)
end

gem install net-ping

Regards,

Dan
 
H

Heinrich Piard

Daniel said:
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 = '(e-mail address removed)'

class SimpleMailer < ActionMailer::Base
def simple_message(recipient)
from '(e-mail address removed)'
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
 
A

Andrew Doades

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
 
D

Daniel Berger

Andrew said:
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
 
A

Andrew Doades

Daniel said:
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)
 
A

Andrew Doades

Andrew said:
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
 
A

Andrew Doades

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,076
Messages
2,570,565
Members
47,201
Latest member
IvyTeeter

Latest Threads

Top