def self.network_interfaces
bytes = `netstat -ibq`.lines.grep(/<Link>/)
pkgs = `netstat -iqd`.lines.grep(/<Link>/)
itf = Hash.new { |h, k| h[k] = NetworkInterface.new(k) }
bytes.each do |line|
name, _, _, _, ibytes, obytes = line.split(/\s+/)
itf[name].in_bytes = ibytes.to_i
itf[name].out_bytes = obytes.to_i
end
pkgs.each do |line|
name, _, _, _, _, ierrs, _, oerrs, _, drop = line.split(/\s+/)
itf[name].in_errors = ierrs.to_i
itf[name].in_drops = drop.to_i
itf[name].out_errors = oerrs.to_i
end
itf.each do |name, nic|
if name =~ /lo\d+/
nic.type = NetworkInterface::LOOPBACK_TYPE
else
nic.type = NetworkInterface::ETHERNET_TYPE
end
end
itf.values
end