Get the IP address of the desktop / windows host in WSL2

--

When you are IN the wsl2 and you want to know how to connect to the desktop / the windows host, here is how i did it

hostip=$(wsl.exe hostname -I)

I found lots solutions that were awk’ing the resolve.conf but had the google servers in there.

You need that, when you want to connect to your display server, or use some npipe hacks or else

this worked before (with the an older windows version 11):

hostip=$(ipconfig.exe | grep 'vEthernet (WSL)' -A4 | cut -d":" -f 2 | tail -n1 | sed -e 's/\s*//g')

--

--