Last active
October 13, 2025 01:03
-
-
Save canbingzt/0fac2a51f73ff083a12e34b2f4721793 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| #hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }') | |
| hostip=$(ip route list default | awk '{print $3}') | |
| wslip=$(hostname -I | awk '{print $1}') | |
| port=<PORT> | |
| PROXY_HTTP="http://${hostip}:${port}" | |
| set_proxy(){ | |
| export http_proxy="${PROXY_HTTP}" | |
| export HTTP_PROXY="${PROXY_HTTP}" | |
| export https_proxy="${PROXY_HTTP}" | |
| export HTTPS_proxy="${PROXY_HTTP}" | |
| git config --global http.proxy "${PROXY_HTTP}" | |
| git config --global https.proxy "${PROXY_HTTP}" | |
| } | |
| unset_proxy(){ | |
| unset http_proxy | |
| unset HTTP_PROXY | |
| unset https_proxy | |
| unset HTTPS_PROXY | |
| git config --global --unset http.proxy | |
| git config --global --unset https.proxy | |
| } | |
| test_setting(){ | |
| echo "Host ip:" ${hostip} | |
| echo "WSL ip:" ${wslip} | |
| echo "Current proxy:" $https_proxy | |
| } | |
| if [ "$1" = "set" ] | |
| then | |
| set_proxy | |
| elif [ "$1" = "unset" ] | |
| then | |
| unset_proxy | |
| elif [ "$1" = "test" ] | |
| then | |
| test_setting | |
| else | |
| echo "Unsupported arguments." | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| :: Check administrator privileges | |
| net session >nul 2>&1 | |
| if %errorLevel% neq 0 ( | |
| echo Require administrator privileges | |
| powershell -NoProfile -Command "& {Start-Process cmd -ArgumentList '/c \"%~f0\"' -Verb RunAs}" | |
| exit /b | |
| ) | |
| echo Start docker... | |
| cmd /c wsl --exec dbus-launch true | |
| :: cmd /c wsl --exec sudo service docker start | |
| echo Config firewall... | |
| powershell -NoProfile -c "Remove-NetFirewallRule -DisplayName \"WSL\";New-NetFirewallRule -DisplayName \"WSL\" -Direction Inbound -InterfaceAlias \"vEthernet (WSL (Hyper-V firewall))\" -Action Allow" | |
| pause |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Remove-NetFirewallRule -DisplayName "WSL" | |
| New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action Allow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very good script, makes my network fine, appreciation comes from China.