Class: Auth::Centric::Firewall::InternetProtocol
- Inherits:
-
Object
- Object
- Auth::Centric::Firewall::InternetProtocol
- Defined in:
- lib/auth/centric/firewall/internet_protocol.rb
Overview
Try to find the IPv4
Instance Method Summary collapse
-
#initialize(request) ⇒ InternetProtocol
constructor
A new instance of InternetProtocol.
- #ip ⇒ Object
- #is_ipv6?(ip_string) ⇒ Boolean
Constructor Details
#initialize(request) ⇒ InternetProtocol
Returns a new instance of InternetProtocol.
10 11 12 |
# File 'lib/auth/centric/firewall/internet_protocol.rb', line 10 def initialize(request) @request = request end |
Instance Method Details
#ip ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/auth/centric/firewall/internet_protocol.rb', line 14 def ip return @ip unless @ip.nil? @ip = @request.env['HTTP_X_REAL_IP'] || @request.env['HTTP_X_FORWARDED_FOR'] || @request.remote_ip return @ip unless @ip.include?(',') @ip.split(',').each do |ip| next if is_ipv6?(ip.strip) @ip = ip.strip break end @ip end |
#is_ipv6?(ip_string) ⇒ Boolean
30 31 32 33 34 |
# File 'lib/auth/centric/firewall/internet_protocol.rb', line 30 def is_ipv6?(ip_string) IPAddr.new(ip_string).ipv6? rescue IPAddr::AddressFamilyError, IPAddr::InvalidAddressError false end |