summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Schroeter <peter.schroeter@rightscale.com>2014-11-18 10:04:49 -0800
committerPeter Schroeter <peter.schroeter@rightscale.com>2014-11-18 10:16:05 -0800
commit349cb7f56e65e8f986d5c807c0f07cf15b149e88 (patch)
treebd3b3e49523cccae943db85fba2022e1f7cd204c
parentb13c4c6a458f4326dd73de380432fbc5e9ce3a77 (diff)
downloadnet-dhcp-ruby-349cb7f56e65e8f986d5c807c0f07cf15b149e88.tar.gz
Extract alternate MAC format from ifconfig
Alternate format appears in CentOS/RHEL7 as well as some BSD variants such as OS X
-rw-r--r--lib/net/dhcp/core.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/net/dhcp/core.rb b/lib/net/dhcp/core.rb
index 95ee7d4..fc27a86 100644
--- a/lib/net/dhcp/core.rb
+++ b/lib/net/dhcp/core.rb
@@ -153,7 +153,11 @@ module DHCP
mac = mac_line.strip.split(":")[1].gsub("-","").strip
end
else
- mac = `/sbin/ifconfig | grep HWaddr | cut -c39- | head -1`.chomp.strip.gsub(/:/,'')
+ ifcfg_out = `/sbin/ifconfig`.chomp
+ matches1 = ifcfg_out.scan(/HWaddr ([a-h0-9:]+)/i).flatten # Linux
+ matches2 = ifcfg_out.scan(/ether ([a-h0-9:]+)/i).flatten # Some Linux (EL7), BSDs
+ mac = matches1.first || matches2.first
+ mac = mac.gsub(/:/,"") if mac
end
mac = '000000000000' if mac.empty?
self.chaddr = [mac].pack('H*').unpack('CCCCCC')