diff options
author | Mark J. Titorenko <nospam-github.com@titorenko.net> | 2014-10-22 19:35:19 +0100 |
---|---|---|
committer | Mark J. Titorenko <nospam-github.com@titorenko.net> | 2014-10-22 19:35:19 +0100 |
commit | d0589c6ff079850e1cde468628c8cd8754f2becb (patch) | |
tree | 9f069e6a6ce983ac31966e06c138fccfd1dab625 | |
parent | b644922a08aa09e2ce75f8f9f9fa1f0b8cecb2e9 (diff) | |
parent | 39d581130023eccf6640a9e3e641a80c438defeb (diff) | |
download | net-dhcp-ruby-d0589c6ff079850e1cde468628c8cd8754f2becb.tar.gz |
Merge pull request #10 from rightscale/dhcp-discover-windows-support
Add Windows support to DHCP requests
-rw-r--r-- | lib/net/dhcp/core.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/net/dhcp/core.rb b/lib/net/dhcp/core.rb index 81cc130..95ee7d4 100644 --- a/lib/net/dhcp/core.rb +++ b/lib/net/dhcp/core.rb @@ -22,6 +22,8 @@ ** =end +require 'rubygems' + module DHCP # -------------------------------------------------------------- dhcp messages class Message @@ -145,7 +147,14 @@ module DHCP self.chaddr = params[:chaddr] raise 'chaddr field should be of 16 bytes' unless self.chaddr.size == 16 else - mac = `/sbin/ifconfig | grep HWaddr | cut -c39- | head -1`.chomp.strip.gsub(/:/,'') + if Gem.respond_to?(:win_platform?) && Gem.win_platform? + mac_line = `getmac /fo list`.split("\n").grep(/Physical Address/).first + if mac_line + mac = mac_line.strip.split(":")[1].gsub("-","").strip + end + else + mac = `/sbin/ifconfig | grep HWaddr | cut -c39- | head -1`.chomp.strip.gsub(/:/,'') + end mac = '000000000000' if mac.empty? self.chaddr = [mac].pack('H*').unpack('CCCCCC') self.chaddr += [0x00]*(16-self.chaddr.size) |