Module: Tor::DNSEL
- Defined in:
- lib/tor/dnsel.rb
Overview
Tor DNS Exit List (DNSEL) client.
Unless the target IP address and port are explicitly specified, the query will be performed using a target IP address of “8.8.8.8” and a target port of 53. These correspond to the DNS protocol port on one of the [Google Public DNS](code.google.com/speed/public-dns/) servers, and they are guaranteed to be reachable from Tor’s default exit policy.
Constant Summary collapse
- RESOLVER =
Resolv::DefaultResolver
- TARGET_ADDR =
Google Public DNS
'8.8.8.8'.freeze
- TARGET_PORT =
DNS
53- DNS_SUFFIX =
'ip-port.exitlist.torproject.org'.freeze
Class Method Summary collapse
-
.dnsname(host, options = {}) ⇒ String
(also: hostname)
Returns the DNS name used for Tor DNSEL queries of ‘host`.
-
.include?(host, options = {}) ⇒ Boolean
Returns ‘true` if the Tor DNSEL includes `host`, `false` otherwise.
-
.query(host, options = {}) ⇒ 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, options = {}) ⇒ String Also known as: hostname
Returns the DNS name used for Tor DNSEL queries of ‘host`.
104 105 106 107 108 109 |
# File 'lib/tor/dnsel.rb', line 104 def self.dnsname(host, = {}) source_addr = getaddress(host, true) target_addr = getaddress([:addr] || TARGET_ADDR, true) target_port = [:port] || TARGET_PORT [source_addr, target_port, target_addr, DNS_SUFFIX].join('.') end |
.include?(host, options = {}) ⇒ Boolean
Returns ‘true` if the Tor DNSEL includes `host`, `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.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tor/dnsel.rb', line 61 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, options = {}) ⇒ 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.
89 90 91 |
# File 'lib/tor/dnsel.rb', line 89 def self.query(host, = {}) getaddress(dnsname(host, )) end |