diff options
author | David Schmitt <david@dasz.at> | 2010-06-14 17:05:20 +0200 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2010-06-15 01:25:36 +1000 |
commit | 83b3ea6abbd1d382a6738fa731f9f7409867e135 (patch) | |
tree | 11158a2f610dba94c839809d5ea86ce5d3de6188 /lib/facter/macaddress.rb | |
parent | ffcae46df5d5336995348544139540c0e564ae2e (diff) | |
download | facter-83b3ea6abbd1d382a6738fa731f9f7409867e135.tar.gz facter-83b3ea6abbd1d382a6738fa731f9f7409867e135.tar.xz facter-83b3ea6abbd1d382a6738fa731f9f7409867e135.zip |
Fixed #3393 - Updates to Facter for MS Windows
This patch is originally by Daniel Berger <djberg96@gmail.com>, I
changed using Facter.value instead of repeatedly testing
Config['host_os'], removed Resolution::which, and fixed the specs.
Thanks to Paul Nasrat for helping with cross-platform debugging.
Signed-off-by: David Schmitt <david@dasz.at>
Diffstat (limited to 'lib/facter/macaddress.rb')
-rw-r--r-- | lib/facter/macaddress.rb | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index e8f40dc..889feea 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb @@ -67,13 +67,26 @@ end Facter.add(:macaddress) do confine :kernel => %w(windows) setcode do - ether = [] - output = %x{ipconfig /all} - output.split(/\r\n/).each do |str| - if str =~ /.*Physical Address.*: (\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2})/ - ether.push($1.gsub(/-/, ":")) - end - end - ether[0] + require 'win32ole' + require 'socket' + + ether = nil + host = Socket.gethostname + connect_string = "winmgmts://#{host}/root/cimv2" + + wmi = WIN32OLE.connect(connect_string) + + query = %Q{ + select * + from Win32_NetworkAdapterConfiguration + where IPEnabled = True + } + + wmi.ExecQuery(query).each{ |nic| + ether = nic.MacAddress + break + } + + ether end end |