Method: PSWindows::Exec#get_ip

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

#get_ipObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/beaker/host/pswindows/exec.rb', line 63

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