I am in charge of a few live websites made in Ruby on Rails. I have a few IP adresses that keep attacking these sites and I would like to block their IP adresses. I know they can get around this wall with a proxy but I do wish to make it harder for them and would love to know where I need to set this up in my ruby on rails app. Thank you everyone!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
class ApplicationController < ActionController::Base
before_filter :block_ip_addresses
protected
def block_ip_addresses
head :unauthorized if current_ip_address == "XX.XX.XX.XX"
end
def current_ip_address
request.env['HTTP_X_REAL_IP'] || request.env['REMOTE_ADDR']
end
end
Thanks to: https://stackoverflow.com/a/10895438/1466095