Class: TorDetector::Base

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

Overview

tor_detector = TorDetector::Base.new tor_detector.call(‘1.2.3.4’)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dns_ip = '8.8.8.8', dns_port = 53, timeout = 5) ⇒ Base

Returns a new instance of Base.



17
18
19
20
21
# File 'lib/tor_detector/base.rb', line 17

def initialize(dns_ip = '8.8.8.8', dns_port = 53, timeout = 5)
  @dns_ip   = dns_ip
  @dns_port = dns_port
  @timeout  = timeout
end

Instance Attribute Details

#dns_ipObject (readonly)

Returns the value of attribute dns_ip.



13
14
15
# File 'lib/tor_detector/base.rb', line 13

def dns_ip
  @dns_ip
end

#dns_portObject (readonly)

Returns the value of attribute dns_port.



13
14
15
# File 'lib/tor_detector/base.rb', line 13

def dns_port
  @dns_port
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



13
14
15
# File 'lib/tor_detector/base.rb', line 13

def timeout
  @timeout
end

Instance Method Details

#call(ip) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tor_detector/base.rb', line 23

def call(ip)
  IPAddr.new(ip)
  Timeout.timeout(timeout) do
    Resolv.getaddress(tor_hostname_for(ip)) == positive_tor_ip
  end
rescue Timeout::Error
  raise DNSTimeout
rescue IPAddr::InvalidAddressError
  raise MalformedIP
rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Resolv::ResolvError
  false
end