Skip to content

Instantly share code, notes, and snippets.

@rodrigonehring
Created July 10, 2019 21:11
Show Gist options
  • Save rodrigonehring/4151cc9a042b2fa30f12e80866e94b49 to your computer and use it in GitHub Desktop.
Save rodrigonehring/4151cc9a042b2fa30f12e80866e94b49 to your computer and use it in GitHub Desktop.
Update etc/hosts with current wsl2 ip
echo OFF
set folder="C:\Users\rodri\Desktop\ip"
del "%folder%\hosts"
ubuntu1804 -c "ip addr | grep 'eth0' | grep 'inet' | grep -o -P 'inet.{0,14}' | grep -E -o '([0-9]{1,3}[\.]){3}[0-9]{1,3}'" > "%folder%\ip.txt"
set /p ip=<"%folder%\ip.txt"
echo %ip%
echo f | copy /Y "%folder%\hosts-copy" "%folder%\hosts"
(echo. & echo %ip% local.gofind) >> %folder%\hosts
copy /Y "%folder%\hosts" "C:\Windows\System32\drivers\etc\hosts"
PAUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment