Menu

#55 Provide DISPLAY IP somehow

open
nobody
None
5
2021-11-12
2021-11-12
No

With WSL/Docker/etc on windows, VcXsvr is quite handy.

However when my computer changes IP/is reconnected to the network, my script does not always find the correct IP. I also suspect that the XServer is not listening on all IPs anymore. 'localhost" is not a good address for the VM as inside the VM that is the VM itself.

Here is my script to get the DISPLAY variable to provide to a VM (under cygwin, code for windows batch in comment):

# Source: https://stackoverflow.com/questions/5898763/how-do-i-get-the-ip-address-into-a-batch-file-variable for the windows version:
# In case of windows batch
# for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set NetworkIP=%%a
# echo Network IP: %NetworkIP
IP=$(ping -4 -n 1 ${COMPUTERNAME}|head -2|tail -1|perl -p -e 's/^.*?\[(.*?)\].*/$1/;')
DISPLAY=$IP:0.0

I see multiple possible approaches (and there are surely other ones):
- The XServer tool saves its IP to a file, and this file is readable;
- The XServer tool detects the IP change and proposes an action, which can also be automatic (by option);
- There is a command API to get the IP for the server.
- The XServer would be listening on its own adapter.

Those could help to access the XServer from VMs.

Discussion


Log in to post a comment.