Class: ProxiesScanner::Proxy
- Inherits:
-
Object
- Object
- ProxiesScanner::Proxy
- Defined in:
- lib/proxies-scanner/proxy.rb
Constant Summary collapse
- CHECK_URL =
'http://www.google.fr'
- TIMEOUT =
10
- STATUS_NOT_TESTED =
"N.TESTED"
- STATUS_OPEN =
"OPEN"
- STATUS_FILTERED =
"FILTERED"
- STATUS_TIMEOUT =
"TIME OUT"
- STATUS_SOCKERROR =
"CLOSED"
- STATUS_STR_MAX_LENGTH =
STATUS_NOT_TESTED.length
Instance Attribute Summary collapse
-
#area ⇒ Object
Returns the value of attribute area.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#port ⇒ Object
Returns the value of attribute port.
-
#response_time ⇒ Object
Returns the value of attribute response_time.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #check ⇒ Object
- #format ⇒ Object
-
#initialize(ip, port, area = '--', status = STATUS_NOT_TESTED) ⇒ Proxy
constructor
A new instance of Proxy.
- #to_s ⇒ Object
Constructor Details
#initialize(ip, port, area = '--', status = STATUS_NOT_TESTED) ⇒ Proxy
Returns a new instance of Proxy.
17 18 19 20 |
# File 'lib/proxies-scanner/proxy.rb', line 17 def initialize(ip, port, area='--', status=STATUS_NOT_TESTED) @ip, @port, @area, @status = ip, port, area, status @response_time = -1 end |
Instance Attribute Details
#area ⇒ Object
Returns the value of attribute area.
4 5 6 |
# File 'lib/proxies-scanner/proxy.rb', line 4 def area @area end |
#ip ⇒ Object
Returns the value of attribute ip.
4 5 6 |
# File 'lib/proxies-scanner/proxy.rb', line 4 def ip @ip end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/proxies-scanner/proxy.rb', line 4 def port @port end |
#response_time ⇒ Object
Returns the value of attribute response_time.
4 5 6 |
# File 'lib/proxies-scanner/proxy.rb', line 4 def response_time @response_time end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/proxies-scanner/proxy.rb', line 4 def status @status end |
Instance Method Details
#check ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/proxies-scanner/proxy.rb', line 30 def check $logger.debug "check proxy: #{self}" uri = URI.parse(CHECK_URL) Timeout::timeout(TIMEOUT) do beginning_time = Time.now http = Net::HTTP::Proxy @ip, @port body = http.get_response(uri).body end_time = Time.now @response_time = (end_time - beginning_time)*1000 t = Nokogiri::HTML(body).search('title') if !t.nil? && !t[0].nil? && t[0].text.downcase.include?('google') $logger.debug "Proxy TITLE: #{t[0].text}" $logger.debug 'Proxy open' @status = Proxy::STATUS_OPEN else $logger.debug 'Proxy filtered' @status = Proxy::STATUS_FILTERED end end rescue SignalException => e raise e rescue Timeout::Error => e @status = Proxy::STATUS_TIMEOUT $logger.info "** Proxies.check: timeout: #{self}" rescue Exception => e @status = Proxy::STATUS_SOCKERROR $logger.error "** Proxies.check: #{e.} proxy=#{self}" end |
#format ⇒ Object
26 27 28 |
# File 'lib/proxies-scanner/proxy.rb', line 26 def format ProxyFormater.fetch(self) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/proxies-scanner/proxy.rb', line 22 def to_s "#{@ip}:#{@port} [#{@area}] [#{@status}]" end |