Programmatic IP Discovery for VZVirtualMachine in an App Store Sandbox

Hi everyone,

I am developing a macOS virtualization manager (VirtualProg) using the Virtualization.framework. The application is distributed via the Mac App Store, so it operates strictly within the App Store Sandbox.

I am looking for a reliable, programmatic way to discover the IP address assigned to a guest (both macOS and Linux).

Is there a recommended "Sandbox-safe" API or pattern within the Virtualization framework—or a lower-level networking entitlement—that allows a host application to retrieve the guest's assigned IP address?

Ideally, I am looking for a solution that does not require the user to manually install a non-sandboxed helper tool.

Thanks in advance for any insights or guidance!

Answered by DTS Engineer in 883963022

i [want] to determine ip address of guest os without any cooperation from guest.

Thanks for confirming that.

This is a fundamentally tricky problem to solve, at least in the general case. The guest chooses how it’s going to assign IP addresses to an interface, and the host has no direct control over that choice.

However, there may be an indirect way to do this:

  • Virtualization framework lets you create a network that’s backed by a vmnet network (VZVmnetNetworkDeviceAttachment).
  • vmnet framework lets your configure a network with a specific DHCP mapping (vmnet_network_configuration_add_dhcp_reservation).

There are some significant caveats:

  • The guest must default to using DHCP.
  • You can’t support bridged mode (VMNET_BRIDGED_MODE), because in bridged mode the guest isn’t talking to the vmnet DHCP server.
  • This is all new in macOS 26.

But otherwise I think it’ll work. So please try it out and let me know how you get along.

ps It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I want to make sure I understand your requirements here. You don’t expect to be running any helper code within the guest, right? So you want to discover the IP address (well, addresses) that the guest OS assigned to the shared interface without any cooperation from the guest?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

i [want] to determine ip address of guest os without any cooperation from guest.

Thanks for confirming that.

This is a fundamentally tricky problem to solve, at least in the general case. The guest chooses how it’s going to assign IP addresses to an interface, and the host has no direct control over that choice.

However, there may be an indirect way to do this:

  • Virtualization framework lets you create a network that’s backed by a vmnet network (VZVmnetNetworkDeviceAttachment).
  • vmnet framework lets your configure a network with a specific DHCP mapping (vmnet_network_configuration_add_dhcp_reservation).

There are some significant caveats:

  • The guest must default to using DHCP.
  • You can’t support bridged mode (VMNET_BRIDGED_MODE), because in bridged mode the guest isn’t talking to the vmnet DHCP server.
  • This is all new in macOS 26.

But otherwise I think it’ll work. So please try it out and let me know how you get along.

ps It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you for the reply. Is there any example with code on how to do this?

never mind i managed to get the sample code from apple container github repository. now i can reserve a pool of ip address and assign ip address to guest from that. thanks for the heads up. it seem to be that VZVmnetNetworkDeviceAttachment is only avaialble for mac os 26 how can accomplist this with 14 and 15. any idea?

And aslo after doing this i would like to do the port forwarding. Any idea how can i accomplish this.

Programmatic IP Discovery for VZVirtualMachine in an App Store Sandbox
 
 
Q