Thanks for your answer. This works, but what I am actually looking for is a method to configure a port forwarding rule like in the GUI.
In the GUI it is possible to assign a port forwarding rule to an interface of a VM which is configured as NAT with the following parameters:
Name: xyz
Protocol: TCP
Host IP: <blank>
Host Port: 2222
Guest IP: <blank>
Guest Port: 22
So if the above mentioned port forwarding has been configured for a machine "Ubuntu" the port forwarding works for this machine without specifying Guest IP/Host IP.
As the machine will receive its IP via DHCP I do not know the Guest IP in advance, which makes it impossible to specify it in the python method.
Actually I have written a short method which will use VBoxMange via 'commands' to configure the port forwarding now:
Code: Select all
def addPortForward(VmName, IfNumber, PfName, Proto, HostPort, GuestPort):
commandString = "VBoxManage modifyvm " + VmName + " --natpf" + str(IfNumber) + " \"'" + str(PfName) + "'," + str(Proto) + ",," + str(HostPort) + ",," + str(GuestPort)+'"'
print commandString
status, output = commands.getstatusoutput(commandString)
print status
print output
I was wondering if the same can be done directly via python API, but it does not seem like that. I also experimented with 'setextradata' but this did not work too well for me.