require 'net/ping' require 'ruby-progressbar' class ProxyFinder def initialize @progressbar end def start(files) infile = File.open(files[:infile], 'r') outfile = File.open(files[:outfile], 'a') # Get number of lines in file to set the progress bar's width # Rewind the file pointer because apparently `count` advances it to the end lines = infile.count infile.rewind @progressbar = ProgressBar.create(title: 'Checking hosts...', format: '%a |%b>>%i| %p%% %t', length: 80, total: lines) infile.readlines.map {|line| line.rstrip}.each do |host| # Displaying progress @progressbar # Extracting IP Address and Port from host ip, port = host.split(':') port = 80 if port.nil? # Carriage return, blanking up to last host length, carriage return if Net::Ping::HTTP.new(ip, port).ping? outfile.puts host end @progressbar.increment end infile.close outfile.close end end