Module: Tor::DNSEL
- Defined in:
- lib/tor/dnsel.rb
Constant Summary collapse
- RESOLVER =
Resolv::DefaultResolver
- DNS_SUFFIX =
'dnsel.torproject.org'.freeze
Class Method Summary collapse
-
.dnsname(host) ⇒ String
(also: hostname)
Returns the DNS name used for Tor DNSEL queries of ‘host`.
-
.include?(host) ⇒ Boolean
Returns ‘true` if `host` is a Tor Exit Node, `false` otherwise.
-
.query(host) ⇒ String
Queries the Tor DNSEL for ‘host`, returning “172.0.0.2” if it is an exit node and raising a `Resolv::ResolvError` if it isn’t.
Class Method Details
.dnsname(host) ⇒ String Also known as: hostname
Returns the DNS name used for Tor DNSEL queries of ‘host`.
58 59 60 61 |
# File 'lib/tor/dnsel.rb', line 58 def self.dnsname(host) source_addr = getaddress(host, true) "#{source_addr}.#{DNS_SUFFIX}" end |
.include?(host) ⇒ Boolean
Returns ‘true` if `host` is a Tor Exit Node, `false` otherwise.
If the DNS server is unreachable or the DNS query times out, returns ‘nil` to indicate that we don’t have a definitive answer one way or another.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tor/dnsel.rb', line 21 def self.include?(host) begin query(host) == '127.0.0.2' rescue Resolv::ResolvError # NXDOMAIN false rescue Resolv::ResolvTimeout nil rescue Errno::EHOSTUNREACH nil rescue Errno::EADDRNOTAVAIL nil end end |
.query(host) ⇒ String
Queries the Tor DNSEL for ‘host`, returning “172.0.0.2” if it is an exit node and raising a `Resolv::ResolvError` if it isn’t.
46 47 48 |
# File 'lib/tor/dnsel.rb', line 46 def self.query(host) getaddress(dnsname(host)) end |