Getting IP address of VZVirtioNetworkDeviceConfiguration

Hello,

I am setting up a Linux virtual machine with Virtualization framework. It works fine. Here is how i am creating a network interface:

let network_device = VZVirtioNetworkDeviceConfiguration()
network_device.attachment = VZNATNetworkDeviceAttachment()
vm_config.networkDevices = [network_device]

As you can see, this is a NAT network. I would like to know the IP address assigned to this interface. macOS emulates a DHCP server and i would like to know the IP in my Xcode program.

How can i do that ?

Thanks

Replies

There is no API to know what IP address was assigned.

A method to get the IP has been to just have the guest report it back through a host-guest channel (serial, Virtio Socket, etc). Another way is to get the IP from ARP based on the MAC address.

Ok and is there a way to get the MAC address of the virtual machine from host program ? Thanks

You should be able to use https://developer.apple.com/documentation/virtualization/vznetworkdeviceconfiguration/3656653-macaddress?language=objc to get the virtual machine mac address.

You can then parse /var/db/dhcpd_leases and lookup this mac address to find the IP which was assigned to the VM.

Post not yet marked as solved Up vote reply of teuf Down vote reply of teuf