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)


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

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)


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

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)


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

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