Method: #arp_table

Defined in:
lib/vagrant-subutai/packer/subutai_net.rb

#arp_tableObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/vagrant-subutai/packer/subutai_net.rb', line 72

def arp_table
  broadcast_ping(2)
  arp_table = {}

  if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin|darwin/
    `arp -a`.split("\n").each do |line|
      matches = /.*(\d+\.\d+\.\d+.\d+)[[:space:]]((([a-f]|[0-9]){1,2}:){5}([a-f]|[0-9]){1,2})[[:space:]].*/.match(line) \
      if (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
      matches = /.*\((\d+\.\d+\.\d+.\d+)\) at ((([a-f]|[0-9]){1,2}:){5}([a-f]|[0-9]){1,2}) .*/.match(line) \
      if (RbConfig::CONFIG['host_os'] =~ /darwin/)

      if ! matches.nil? && ! matches[2].nil?
        key_mac = zero_pad_mac(matches[2])
        value_ip = matches[1]
        arp_table.store(key_mac, value_ip)
      end
    end
  elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
    `ip n | awk '{print $1,$5}'`.split("\n").each do |line|
      ip, mac = line.split(' ')

      if ! line.nil? && ! mac.nil?

        key_mac = zero_pad_mac(mac)
        value_ip = ip
        arp_table.store(key_mac, value_ip)
      end
    end
  end

  arp_table
end