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写的,我只是个搬运工~

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