Created
April 15, 2013 11:52
-
-
Save seyhunak/5387545 to your computer and use it in GitHub Desktop.
IP Range Checker
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 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