Method: PSWindows::Exec#get_ip

Defined in:
lib/beaker/host/pswindows/exec.rb

#get_ipObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/beaker/host/pswindows/exec.rb', line 44

def get_ip
  # when querying for an IP this way the return value can be formatted like:
  # IPAddress=
  # IPAddress={"129.168.0.1"}
  # IPAddress={"192.168.0.1","2001:db8:aaaa:bbbb:cccc:dddd:eeee:0001"}

  ips = execute("wmic nicconfig where ipenabled=true GET IPAddress /format:list")

  ip = ''
  ips.each_line do |line|
    matches = line.split('=')
    next if matches.length <= 1
    matches = matches[1].match(/^{"(.*?)"/)
    next if matches.nil? || matches.captures.nil? || matches.captures.empty?
    ip = matches.captures[0] if matches && matches.captures
    break if ip != ''
  end

  ip
end