Module: Ohai::Util::IpHelper

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

Constant Summary collapse

IPAddress("fe80::/10")
IPV6_PRIVATE_ADDRESS_BLOCK =
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

Returns:

  • (Boolean)


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

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?

Returns:

  • (Boolean)


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

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

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

#public_address?(addr) ⇒ Boolean

Returns:

  • (Boolean)


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

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