Created
August 26, 2013 06:55
-
-
Save chsh/6338687 to your computer and use it in GitHub Desktop.
Verify facebook crawler ip range.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ipaddr' | |
class FacebookIPRange | |
def self.zones | |
@@zones ||= build_zones | |
end | |
def self.match(ipaddr) | |
zones.each do |zone| | |
return true if zone === ipaddr | |
end | |
false | |
end | |
def self.build_zones | |
zones = [] | |
lines = `whois -h whois.radb.net -- '-i origin AS32934' | grep ^route`.split(/\n/) | |
lines.each do |line| | |
if line =~ /route:\s*(\d+\.\d+\.\d+\.\d+\/\d+)/ | |
zones << $1 | |
end | |
end | |
zones_to_ipaddrs zones | |
end | |
def self.zones_to_ipaddrs(zones) | |
zones.map { |zone| IPAddr.new zone } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment