Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Created April 15, 2013 11:52
Show Gist options
  • Save seyhunak/5387545 to your computer and use it in GitHub Desktop.
Save seyhunak/5387545 to your computer and use it in GitHub Desktop.
IP Range Checker
require 'ipaddr'
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :redirect_if_bolivia
private
def redirect_if_bolivia
if bolivian_blocks.any? { |block| block.include?(request.remote_ip) }
#redirect user to www.foo.com
end
end
def bolivian_blocks
%w{
12.144.86.0/23
31.201.1.176/30
}.map { |subnet| IPAddr.new subnet }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment