Module: Ohai::Util::IpHelper

Defined in:
lib/ohai/util/ip_helper.rb

Constant Summary collapse

IPV6_PRIVATE_ADDRESS_BLOCK =

Corresponding to RFC 4193

IPAddress('fc00::/7')

Instance Method Summary collapse

Instance Method Details

#loopback?(addr) ⇒ Boolean

The ipaddress gem doesn't implement loopback? for IPv4 addresses github.com/bluemonk/ipaddress/issues/25


43
44
45
46
47
48
49
50
51
# File 'lib/ohai/util/ip_helper.rb', line 43

def loopback?(addr)
  ip = IPAddress(addr)

  if ip.respond_to? :loopback?
    ip.loopback?
  else
    IPAddress('127.0.0.0/8').include? ip
  end
end

#private_address?(addr) ⇒ Boolean Also known as: unique_local_address?


25
26
27
28
29
30
31
32
33
# File 'lib/ohai/util/ip_helper.rb', line 25

def private_address?(addr)
  ip = IPAddress(addr)

  if ip.respond_to? :private?
    ip.private?
  else
    IPV6_PRIVATE_ADDRESS_BLOCK.include?(ip)
  end
end

#public_address?(addr) ⇒ Boolean


36
37
38
# File 'lib/ohai/util/ip_helper.rb', line 36

def public_address?(addr)
  !private_address?(addr)
end