Skip to content

Instantly share code, notes, and snippets.

@chsh
Created August 26, 2013 06:55
Show Gist options
  • Save chsh/6338687 to your computer and use it in GitHub Desktop.
Save chsh/6338687 to your computer and use it in GitHub Desktop.
Verify facebook crawler ip range.
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