Class: Hooray::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/hooray/local.rb

Overview

Information from the machine

Class Method Summary collapse

Class Method Details

.arp_tableObject

ARP Table reader



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hooray/local.rb', line 10

def arp_table
  return @arp_table if @arp_table
  @arp_table ||= {}
  `arp -na`.split(/\n/).each do |l|
    _q, ip, _at, mac, *iface = l.split(/\s+/)
    next unless mac =~ /:\w{2}:/
    ip = ip[1..-2] # (ip) -> ip
    @arp_table.merge!(ip => mac) if iface
  end
  @arp_table
end

.ipsObject



22
23
24
25
26
# File 'lib/hooray/local.rb', line 22

def ips
  Socket.ip_address_list.select do |ip|
    ip.ipv4_private? && !ip.ipv4_loopback?
  end
end

.lan_ipObject



28
29
30
# File 'lib/hooray/local.rb', line 28

def lan_ip
  IPAddr.new(ips.first.ip_address)
end

.mask(bits = 24) ⇒ Object



32
33
34
# File 'lib/hooray/local.rb', line 32

def mask(bits = 24)
  lan_ip.mask(bits)
end