Last active
January 3, 2024 13:28
-
-
Save SimZhou/8612c013e9ddb2fe6844f6efac5a6e42 to your computer and use it in GitHub Desktop.
A linux shell proxy set/unset script
This file contains 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
# Save following lines as '/usr/local/sbin/ssr-on' | |
# Enable proxy using command: . ssr-on | |
proxy_list=( | |
http://username:[email protected]:1080 | |
http://192.168.1.11:1080 | |
) | |
for proxy in ${proxy_list[@]}; do | |
ip_addr=$(echo $proxy | sed -re 's|^http://||g;s|.*@||g;s|:[0-9]*/?$||g') | |
port=$(echo $proxy | awk '{port=gensub(/.*:([0-9]{1,5})\/?/,"\\1","g",$0);print port}') | |
nc -vz -w 1 $ip_addr $port &> /dev/null && { | |
export http_proxy=$proxy HTTP_PROXY=$proxy https_proxy=$proxy HTTPS_PROXY=$proxy | |
git config --global http.proxy $proxy | |
echo "Proxy Server Set to $proxy" && return | |
} | |
done | |
echo "No Alive Proxy Server Found!" | |
# to set proxy for apt update, see: | |
# /etc/apt/apt.conf.d/87proxy # reference: https://askubuntu.com/a/920242/1410764 | |
# Save following lines as '/usr/local/sbin/ssr-off' | |
# Disable proxy using command: . ssr-off | |
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY | |
git config --global --unset http.proxy | |
echo "Proxy Server Dismissed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wget supports lowercase http_proxy only, and docker uses uppercase.
So it is recommended to set both upper and lower cases...
Reference: https://unix.stackexchange.com/a/212972/525088