Class: Legitbot::BotMatch
- Inherits:
-
Object
- Object
- Legitbot::BotMatch
show all
- Defined in:
- lib/legitbot/botmatch.rb
Overview
Represents a bot instance match. Typical methods are valid?, fake? and detected_as
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ip, resolver_config = nil) ⇒ BotMatch
Returns a new instance of BotMatch.
10
11
12
13
|
# File 'lib/legitbot/botmatch.rb', line 10
def initialize(ip, resolver_config = nil)
@dns = Resolv::DNS.new(resolver_config)
@ip = ip
end
|
Class Method Details
.fake?(ip, resolver_config = nil) ⇒ Boolean
63
64
65
|
# File 'lib/legitbot/botmatch.rb', line 63
def self.fake?(ip, resolver_config = nil)
self.new(ip, resolver_config).fake?
end
|
.valid?(ip, resolver_config = nil) ⇒ Boolean
59
60
61
|
# File 'lib/legitbot/botmatch.rb', line 59
def self.valid?(ip, resolver_config = nil)
self.new(ip, resolver_config).valid?
end
|
Instance Method Details
#detected_as ⇒ Object
51
52
53
|
# File 'lib/legitbot/botmatch.rb', line 51
def detected_as
self.class.name.split('::').last.downcase.to_sym
end
|
#fake? ⇒ Boolean
55
56
57
|
# File 'lib/legitbot/botmatch.rb', line 55
def fake?
!valid?
end
|
#reverse_domain ⇒ Object
Returns a Resolv::DNS::Name instance with the reverse name
18
19
20
21
22
|
# File 'lib/legitbot/botmatch.rb', line 18
def reverse_domain
@reverse_domain ||= @dns.getname(@ip)
rescue Resolv::ResolvError
@reverse_domain ||= nil
end
|
#reverse_name ⇒ Object
Returns a String with the reverse name
26
27
28
|
# File 'lib/legitbot/botmatch.rb', line 26
def reverse_name
reverse_domain&.to_s
end
|
#reverse_resolves? ⇒ Boolean
39
40
41
|
# File 'lib/legitbot/botmatch.rb', line 39
def reverse_resolves?
@ip == reversed_ip
end
|
#reversed_ip ⇒ Object
Returns a String with IP created from the reverse name
32
33
34
35
36
37
|
# File 'lib/legitbot/botmatch.rb', line 32
def reversed_ip
return nil if reverse_name.nil?
@reverse_ip ||= @dns.getaddress(reverse_name)
@reverse_ip.to_s
end
|
#subdomain_of?(*domains) ⇒ Boolean
43
44
45
46
47
48
49
|
# File 'lib/legitbot/botmatch.rb', line 43
def subdomain_of?(*domains)
return false if reverse_name.nil?
domains.any? { |d|
reverse_domain.subdomain_of? Resolv::DNS::Name.create(d)
}
end
|