[download]

local/bin/vbox-nat

   1 #!/bin/bash
   2 
   3 ssh=2221
   4 
   5 vboxmanage list runningvms | while IFS=\" read _ name id; do
   6     echo "22 -> $(( ++ssh )): $name"
   7 
   8     vboxmanage showvminfo --machinereadable $id |
   9     awk -F '[",]' '/Forwarding/ { print $2 }'   |
  10     xargs -I % vboxmanage controlvm $id natpf1 delete %
  11 
  12     vboxmanage controlvm $id natpf1 "SSH,tcp,,$ssh,,22"
  13 done