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
Thanks to: https://stackoverflow.com/a/10895438/1466095
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With