Module: Pione::Util::IPAddress
- Defined in:
- lib/pione/util/ip-address.rb
Class Method Summary collapse
-
.find ⇒ Array<String>
Find IP address list in the machine.
-
.myself ⇒ String
Return my IP address that PIONE choosed.
Class Method Details
.find ⇒ Array<String>
Find IP address list in the machine. This list includes IPv4 addresses only.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 ⇒ String
Return my IP address that PIONE choosed.
8 9 10 |
# File 'lib/pione/util/ip-address.rb', line 8 def myself find.first end |