Class: ProxyFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_finder.rb

Instance Method Summary collapse

Constructor Details

#initializeProxyFinder

Returns a new instance of ProxyFinder.



6
7
8
# File 'lib/proxy_finder.rb', line 6

def initialize
  @progressbar
end

Instance Method Details

#start(files) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/proxy_finder.rb', line 10

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