module Pione::Util::IPAddress
Public Class Methods
find()
click to toggle source
Find IP address list in the machine. This list includes IPv4 addresses only.
@return [Array<String>]
IP addresses
# File lib/pione/util/ip-address.rb, line 17 def find addrs = Socket.ip_address_list.select do |addr| addr.ipv4? and not(addr.ipv4_loopback?) and not(addr.ipv4_multicast?) end if not(addrs.empty?) privates = addrs.select{|addr| addr.ipv4_private?} not_privates = addrs - privates privates = privates.sort{|a,b| a.ip_address <=> b.ip_address} not_privates = not_privates.sort{|a, b| a.ip_address <=> b.ip_address} (privates + not_privates).map {|addr| addr.ip_address} else Socket.ip_address_list.select{|addr| addr.ipv4_loopback?}.map{|addr| addr.ip_address} end end
myself()
click to toggle source
Return my IP address that PIONE choosed.
@return [String]
my IP address
# File lib/pione/util/ip-address.rb, line 8 def myself find.first end
Private Instance Methods
find()
click to toggle source
Find IP address list in the machine. This list includes IPv4 addresses only.
@return [Array<String>]
IP addresses
# File lib/pione/util/ip-address.rb, line 17 def find addrs = Socket.ip_address_list.select do |addr| addr.ipv4? and not(addr.ipv4_loopback?) and not(addr.ipv4_multicast?) end if not(addrs.empty?) privates = addrs.select{|addr| addr.ipv4_private?} not_privates = addrs - privates privates = privates.sort{|a,b| a.ip_address <=> b.ip_address} not_privates = not_privates.sort{|a, b| a.ip_address <=> b.ip_address} (privates + not_privates).map {|addr| addr.ip_address} else Socket.ip_address_list.select{|addr| addr.ipv4_loopback?}.map{|addr| addr.ip_address} end end
myself()
click to toggle source
Return my IP address that PIONE choosed.
@return [String]
my IP address
# File lib/pione/util/ip-address.rb, line 8 def myself find.first end