Skip to content

Instantly share code, notes, and snippets.

@ThYpHo0n
Last active August 5, 2024 01:37
Show Gist options
  • Save ThYpHo0n/349f1f6473e207b866f65aca4728da3e to your computer and use it in GitHub Desktop.
Save ThYpHo0n/349f1f6473e207b866f65aca4728da3e to your computer and use it in GitHub Desktop.
WSL(2) bash profile helpers
# WSL?
if [[ "$(< /proc/sys/kernel/osrelease)" == *microsoft* ]]; then
export $(dbus-launch)
export LIBGL_ALWAYS_INDIRECT=1
export WSL_VERSION=$(wsl.exe -l -v | grep -a '[*]' | sed 's/[^0-9]*//g')
export WSL_HOST=$(tail -1 /etc/resolv.conf | cut -d' ' -f2)
export DISPLAY=$WSL_HOST:0
# pip path if using --user
export PATH=$PATH:$HOME/.local/bin
# SSH
eval $(/mnt/c/weasel-pageant/weasel-pageant -r)
fi
@boypt
Copy link

boypt commented Apr 6, 2021

if /etc/resolve.conf can't get what you want, iproute2 util is another proper way to get the gateway address:

 ip -o route get 1.1.1.1 | cut -d' ' -f 3

the 1.1.1.1 can be any address of foreign network, it just show how kernel visit that address.

@crkolimago
Copy link

export DISPLAY=$(ipconfig.exe | grep IPv4 | head -1 | rev | awk '{print $1}' | rev | tr -d '\r'):0.0

I used this approach but added a grep to extract just the Wi-Fi adapter because the IPv4 part was just fetching the first match so:

export DISPLAY=$(ipconfig.exe | grep -A 6 'Wireless LAN adapter Wi-Fi' | grep IPv4 | head -1 | rev | awk '{print $1}' | rev | tr -d '\r'):0.0

@smerschjohann
Copy link

smerschjohann commented Nov 3, 2021

I came up with this: HOST_IP=$(route.exe print | grep "0.0.0.0 0.0.0.0" | awk '{print $4}')

I changed the routing inside my wsl as a workaround for my VPN software. So there is no way to get the Windows external IP on the linux side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment