Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8075815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:06:53+00:00 2026-06-05T15:06:53+00:00

As the title goes, you can get the client’s ip with both methods. I

  • 0

As the title goes, you can get the client’s ip with both methods. I wonder if there is any differences. Thank you.

in the source code there goes

“/usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.3/lib/action
_dispatch/http/request.rb” 257L, 8741C

def ip
  @ip ||= super
end

# Originating IP address, usually set by the RemoteIp middleware.
def remote_ip
  @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
end

but I really don’t know the implications.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:06:56+00:00Added an answer on June 5, 2026 at 3:06 pm

    From source:

    module ActionDispatch
      class Request < Rack::Request
    
        # ...
    
        def ip
          @ip ||= super
        end
    
        def remote_ip
          @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
        end
    
        # ...
    
      end
    end
    

    where Rack::Request looks like this

    module Rack
      class Request
         def ip
          remote_addrs = split_ip_addresses(@env['REMOTE_ADDR'])
          remote_addrs = reject_trusted_ip_addresses(remote_addrs)
    
          return remote_addrs.first if remote_addrs.any?
    
          forwarded_ips = split_ip_addresses(@env['HTTP_X_FORWARDED_FOR'])
    
          if client_ip = @env['HTTP_CLIENT_IP']
            # If forwarded_ips doesn't include the client_ip, it might be an
            # ip spoofing attempt, so we ignore HTTP_CLIENT_IP
            return client_ip if forwarded_ips.include?(client_ip)
          end
    
          return reject_trusted_ip_addresses(forwarded_ips).last || @env["REMOTE_ADDR"]
        end
      end
    end 
    

    So remote_ip gives precedence to action_dispatch.remote_ip. That is being set by ActionDispatch::RemoteIp middleware. You can see in that middleware’s source that it’s checking for spoofing attacks when being called, since it’s calling GetIp.new to set that env variable. That’s needed since remote_ip reads the ip address even through the local proxies, as Clowerweb explains.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title goes I am trying something like $(ul li:nth-child(' + xx +
Alright, hard to phrase an exact title for this question, but here goes... I
OK, I don't think the title says it right... but here goes: I have
Title pretty much sums it up. Is there a technical name given to a
Title is most of the question, what allows this to be valid code? Is
I have the following string: h3. My Title Goes Here I basically want to
hope can help, trying out Jquery clone which seems to work, but I get
I'm not sure how to title my question, but here goes. I am testing
I can't get my textbox to update the database. The changes look like they
Here are the codes public class MyModel { [Required] public string Title {get;set;} }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.