Class: Legitbot::Facebook
Overview
Constant Summary
collapse
- AS =
'AS32934'
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BotMatch
#detected_as, #fake?, fake?, #initialize, #reverse_domain, #reverse_name, #reverse_resolves?, #reversed_ip, #subdomain_of?, valid?
Class Method Details
.load_ips ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/legitbot/facebook.rb', line 26
def self.load_ips
whois.map do |(family, records)|
ranges = records.map do |cidr|
range = IPAddr.new(cidr).to_range
(range.begin.to_i..range.end.to_i)
end
[family, IntervalTree::Tree.new(ranges)]
end.to_h
end
|
.reload! ⇒ Object
22
23
24
|
# File 'lib/legitbot/facebook.rb', line 22
def self.reload!
@mutex.synchronize { @ips = load_ips }
end
|
.valid_ips ⇒ Object
18
19
20
|
# File 'lib/legitbot/facebook.rb', line 18
def self.valid_ips
@mutex.synchronize { @ips ||= load_ips }
end
|
.whois ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/legitbot/facebook.rb', line 36
def self.whois
client = Irrc::Client.new
client.query :radb, AS
results = client.perform
%i(ipv4 ipv6).map do |family|
[family, results[AS][family][AS]]
end.to_h
end
|
Instance Method Details
#valid? ⇒ Boolean
11
12
13
14
|
# File 'lib/legitbot/facebook.rb', line 11
def valid?
ip = IPAddr.new(@ip)
Facebook.valid_ips[ip.ipv4? ? :ipv4 : :ipv6].search(ip.to_i).size > 0
end
|