如何在Ruby on Rails中阻止特定的IP地址 [英] How do you block specific IP adress in Ruby on Rails
本文介绍了如何在Ruby on Rails中阻止特定的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我负责Ruby on Rails上的一些实时网站.我有一些IP地址会继续攻击这些站点,我想阻止他们的IP地址.我知道他们可以通过代理绕过这堵墙,但是我确实想让他们更难,并且很想知道我需要在我的ruby on rails应用程序中进行设置的地方.谢谢大家!
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!
推荐答案
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
感谢: https://stackoverflow.com/a/10895438/1466095
这篇关于如何在Ruby on Rails中阻止特定的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文