This is how I addressed the need to try and select unique ports for the VNC and Spice environments. This is from a Bash script used to start each VM.
#=============================================================================# # Spice and VNC Settings # # # # For each setting use the last octet of the primary MAC/IP Address in # # decimal notation plus the port settings as the default setting. Thus for a # # MAC/IP Address of 52:54:00:10:01:05/172.16.1.5 the settings would be: # # # # Spice Port (SPICEP) : 40000 + (octet5*256) + octet6 # # VNC Port : 5900 + octet6 # # # # The octets converted to decimal notation. # # # #=============================================================================# if [ "${MACADR[ 0]}" != "" ] ; then SAV="${IFS}" IFS="${IFS}:" get_mac_as_decimal 1 ${MACADR[ 0]} OCTET1=$? get_mac_as_decimal 2 ${MACADR[ 0]} OCTET2=$? get_mac_as_decimal 3 ${MACADR[ 0]} OCTET3=$? get_mac_as_decimal 4 ${MACADR[ 0]} OCTET4=$? get_mac_as_decimal 5 ${MACADR[ 0]} OCTET5=$? get_mac_as_decimal 6 ${MACADR[ 0]} OCTET6=$? IFS="${SAV}" OCTET5=$((${OCTET5}*256)) SPICEP=$((40000+${OCTET5}+${OCTET6})) VNCHOST=":${OCTET6}" # Format is [host][:display] MONPIPE="/tmp/.qemu_control_${SPICEP}" # Monitor Pipe SPICEINFO="-spice port=${SPICEP},password=isrdesk" VNCINFO="-vnc ${VNCHOST}" QMPINFO="-qmp unix:${MONPIPE},server,nowait" else echo "MAC Address 0 is not defined. Spice Port, VNC Host and Monitor Pipe" echo "can not be set. Empty values are being set. " SPICEP="" VNCHOST="" MONPIPE="" SPICEINFO="" VNCINFO="" QMPINFO="" fi Don Mahmood Naderan wrote on 01/22/2017 08:23 AM: >>you can run ps -eaf |grep vnc to see whcih all ports being reserved > > Isn't there any easier way? Users are not expert, so do not expect to use ps > command and see which vnc port is free... > > If I don't use vnc, the qemu will bring up the screen. So, the question is > what is the benefit of using vnc? Bu using vnc, I have to open another > terminal and connect to the guest > > Regards, > Mahmood >