Class: EventMachine::DNSBL::Client
- Inherits:
-
Object
- Object
- EventMachine::DNSBL::Client
- Defined in:
- lib/eventmachine/dnsbl/client.rb
Overview
Lookup actually handles the sending of queries to a recursive DNS server and places any replies into DNSBLResults
Constant Summary collapse
- @@config =
EventMachine::DNSBL::Defaults.config
- @@tlds_2l =
EventMachine::DNSBL::Defaults.tlds_2l
- @@tlds_3l =
EventMachine::DNSBL::Defaults.tlds_3l
- @@requests =
Array.new
Class Method Summary collapse
- .blacklisted?(answers) ⇒ Boolean
- .check(item, &cback) ⇒ Object
- .config(config = nil) ⇒ Object
-
.normalize(domain) ⇒ Object
Converts a hostname to the domain: e.g., www.google.com => google.com, science.somewhere.co.uk => somewhere.co.uk.
- .three_level_tlds(three_level_tlds = nil) ⇒ Object
- .two_level_tlds(two_level_tlds = nil) ⇒ Object
Class Method Details
.blacklisted?(answers) ⇒ Boolean
97 98 99 |
# File 'lib/eventmachine/dnsbl/client.rb', line 97 def self.blacklisted?(answers) answers.find {|a| a.meaning } != nil end |
.check(item, &cback) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/eventmachine/dnsbl/client.rb', line 62 def self.check(item, &cback) itemtype = (item =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) ? :ip : :domain label = (itemtype == :ip) ? item.split(/\./).reverse.join(".") : normalize(item) answers = Array.new count = 0 @@config.each do |dnsblname, | if [:type] == itemtype and not [:disabled] count += 1 starttime = Time.now.to_f lookup = "#{label}.#{[:domain]}" d = EM::DNS::Resolver.resolve lookup d.errback { answers << DNSBLResult.new(dnsblname, item, lookup, nil, nil, Time.now.to_f - starttime) if answers.length == count and cback cback.call(answers) end } d.callback { |r| res = nil meaning = nil if r.length > 0 res = r.join(",") meaning = r.map {|answer| [answer] || answer }.join(",") end answers << DNSBLResult.new(dnsblname, item, lookup, res, meaning, Time.now.to_f - starttime) if answers.length == count and cback cback.call(answers) end } end end end |
.config(config = nil) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/eventmachine/dnsbl/client.rb', line 24 def self.config(config = nil) if config @@config = config end @@config end |
.normalize(domain) ⇒ Object
Converts a hostname to the domain: e.g., www.google.com => google.com, science.somewhere.co.uk => somewhere.co.uk
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/eventmachine/dnsbl/client.rb', line 46 def self.normalize(domain) # strip off the protocol (\w{1,20}://), the URI (/), parameters (?), port number (:), and username (.*@) # then split into parts via the . parts = domain.gsub(/^\w{1,20}:\/\//,'').gsub(/[\/\?\:].*/,'').gsub(/.*?\@/,'').split(/\./) # grab the last two parts of the domain dom = parts[-2,2].join(".") # if the dom is in the two_level_tld list, then use three parts if @@tlds_2l.index(dom) dom = parts[-3,3].join(".") end if @@tlds_3l.index(dom) dom = parts[-4,4].join(".") end dom end |
.three_level_tlds(three_level_tlds = nil) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/eventmachine/dnsbl/client.rb', line 38 def self.three_level_tlds(three_level_tlds = nil) if three_level_tlds @@tlds_3l = three_level_tlds end @@tlds_3l end |
.two_level_tlds(two_level_tlds = nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/eventmachine/dnsbl/client.rb', line 31 def self.two_level_tlds(two_level_tlds = nil) if two_level_tlds @@tlds_2l = two_level_tlds end @@tlds_2l end |