require 'ipaddr'
require 'ping'
  
class IPAddr
  
  # Define the next IP address for the current one
  def succ()
    return self.clone.set(@addr + 1)
  end
  
  # Define a comparator for IPAddr. Compare the address fields
  def <=>(other)
    return @addr <=> other.to_i
  end
  
  # Return an array of IPs that match the range beetwin start_ip and end_ip.
  # The start_ip and the end_ip cant be either simple addresses (xxx.xxx.xxx.xxx) or 
  # addresses with mask (xxx.xxx.xxx.xxx/xxx). This function take care of masks if any.
  def self.range(start_ip, end_ip)
    a = IPAddr.new start_ip
    b = IPAddr.new end_ip
    (a..b).to_a
  end

end

def massive_auto_detection(ips)
  alive_ips = []
  ips.each do |ip|
    if Ping.pingecho(ip.to_s, 0.5)
      alive_ips << ip
    end
  end
  alive_ips
end

raise(new( ArgumentException("Il faut passer une ip de départ et une ip de fin !"))) if ARGV.size() < 2

start_ip = ARGV[0]
end_ip = ARGV[1]
ips = IPAddr.range(start_ip, end_ip)
alive_ips = massive_auto_detection(ips)

alive_ips.each do |ip|
  p "This computer is alive ! :  " + ip.to_s
end