Class: ProxyUtilities::Checker

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

Instance Method Summary collapse

Constructor Details

#initialize(ip, port) ⇒ Checker



6
7
8
9
# File 'lib/proxy_utilities/checker.rb', line 6

def initialize(ip, port)
  @ip = ip
  @port = port
end

Instance Method Details

#check_amazon?Boolean



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/proxy_utilities/checker.rb', line 32

def check_amazon?
  begin
    url = "http://amazon.com"
    proxy_connection = Net::HTTP::Proxy(@ip, @port.to_i)
    Timeout.timeout(3) do
      return proxy_connection.start(url).active?
    end
  rescue
    return false
  end
end

#check_any_website(websites) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/proxy_utilities/checker.rb', line 44

def check_any_website(websites)
  result = {}
  proxy_connection = Net::HTTP::Proxy(@ip, @port.to_i)
  websites.each do |website|
    begin
      Timeout.timeout(3) do
        result[website] = proxy_connection.start(website).active?
      end
    rescue
      next
    end
  end
  return result
end

#check_google?Boolean



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/proxy_utilities/checker.rb', line 20

def check_google?
  begin
    url = "http://google.com"
    proxy_connection = Net::HTTP::Proxy(@ip, @port.to_i)
    Timeout.timeout(3) do
      return proxy_connection.start(url).active?
    end
  rescue
    return false
  end
end

#check_online?Boolean



11
12
13
14
15
16
17
18
# File 'lib/proxy_utilities/checker.rb', line 11

def check_online?
  begin
    check = Net::Ping::External.new(host = @ip, port = @port)
    check.ping?
  rescue
    return false
  end
end