Module: Ohai::Util::IpHelper
- Defined in:
- lib/ohai/util/ip_helper.rb
Constant Summary collapse
- IPV6_LINK_LOCAL_UNICAST_BLOCK =
Corresponding to RFC 4192 + RFC 4193
IPAddress("fe80::/10")
- IPV6_PRIVATE_ADDRESS_BLOCK =
IPAddress("fc00::/7")
Instance Method Summary collapse
-
#loopback?(addr) ⇒ Boolean
The ipaddress gem doesn’t implement loopback? for IPv4 addresses github.com/bluemonk/ipaddress/issues/25.
- #private_address?(addr) ⇒ Boolean (also: #unique_local_address?)
- #public_address?(addr) ⇒ Boolean
Instance Method Details
#loopback?(addr) ⇒ Boolean
The ipaddress gem doesn’t implement loopback? for IPv4 addresses github.com/bluemonk/ipaddress/issues/25
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?
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
37 38 39 |
# File 'lib/ohai/util/ip_helper.rb', line 37 def public_address?(addr) !private_address?(addr) end |