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