Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top