Method: Windows::Exec#get_ip

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

#get_ipObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/beaker/host/windows/exec.rb', line 26

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