wsl2下一行命令設置windows代理

  • set_proxy.sh
#!/bin/bash

# Get Windows IP address
WINDOWS_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')

# Set proxy
export http_proxy=http://${WINDOWS_IP}:7890
export https_proxy=http://${WINDOWS_IP}:7890
export all_proxy=socks5://${WINDOWS_IP}:7890

# Test proxy
if curl -sSf https://www.google.com > /dev/null; then
    echo "proxy is working."
	echo "export https_proxy=http://${WINDOWS_IP}:7890;export http_proxy=http://${WINDOWS_IP}:7890;export all_proxy=socks5://${WINDOWS_IP}:7890"
else
    echo "Failed to connect to the Internet through proxy."
fi
  • 運行腳本
# 設置到當前終端
source set_proxy.sh
# 查看代理設置
bash set_proxy.sh

腳本是ai寫的,我只是個搬運工~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章