Hello.
I'm trying to make a small program to ping an IP through TCP/ICMP but
when I run it I get an error.
D:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/net-ping-1.5.2/lib/net/ping/ping.rb:80:in
`ping': no host specified (Argume
ntError)
from
D:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/net-ping-1.5.2/lib/net/ping/tcp.rb:38:in
`ping'
from png.rb:50:in `do_ping_tcp'
from png.rb:19:in `initialize'
from png.rb:61:in `new'
from png.rb:61:in `<main>'
The snip of code which ping works fine if its alone but something gets
messy with the rest of the code and I just don't know what is it. Any
ideas?
require 'rubygems'
require 'net/ping'
include Net
class Ping
def initialize(*argv)
@argv = argv
if @argv[0]=="help" || !@argv[0]
send :help
end
if !@argv[1]
@argv[1]="tcp"
end
# swap with case() later
if @argv[1] == "tcp"
send :do_ping_tcp
elsif @argv[1] == "icmp"
send :do_ping_icmp
end
end
def repeat_every(interval)
loop do
start_time = Time.now
yield
elapsed = Time.now - start_time
sleep([interval - elapsed, 0].max)
end
end
def help
puts <<-help
Commands:
help
end
def do_ping_tcp
Net::Ping::TCP.econnrefused = true
result=Net::Ping::TCP.new('192.168.1.1',80)
if result.ping?
puts "alive..."
else
puts "dead..."
end
end
def do_ping_icmp
end
end
ping = Ping.new(*ARGV)
···
--
Posted via http://www.ruby-forum.com/.