Skip to content

Commit a41ca7c

Browse files
committed
Use vmrun getGuestIPAddress to get IP (Big Sur)
1 parent aaccce5 commit a41ca7c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/drivers/vmware/driver.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ func (d *Driver) GetIP() (ip string, err error) {
123123
return "", drivers.ErrHostIsNotRunning
124124
}
125125

126+
// attempt to find the address from vmrun
127+
if ip, err := d.getIPfromVmrun(); err == nil {
128+
return ip, err
129+
}
130+
126131
// determine MAC address for VM
127132
macaddr, err := d.getMacAddressFromVmx()
128133
if err != nil {
@@ -401,6 +406,18 @@ func (d *Driver) getMacAddressFromVmx() (string, error) {
401406
return macaddr, nil
402407
}
403408

409+
func (d *Driver) getIPfromVmrun() (string, error) {
410+
vmx := d.vmxPath()
411+
412+
ip := regexp.MustCompile(`\d+\.\d+\.\d+\.\d+`)
413+
stdout, _, _ := vmrun("getGuestIPAddress", vmx)
414+
if match := ip.FindString(stdout); match != "" {
415+
return match, nil
416+
}
417+
418+
return "", fmt.Errorf("could not get IP from vmrun")
419+
}
420+
404421
func (d *Driver) getIPfromVmnetConfiguration(macaddr string) (string, error) {
405422

406423
// DHCP lease table for NAT vmnet interface

0 commit comments

Comments
 (0)