Skip to content

Instantly share code, notes, and snippets.

@yankchina
Forked from kernelsmith/proxy_helper.sh
Created January 21, 2014 11:09
Show Gist options
  • Save yankchina/8538162 to your computer and use it in GitHub Desktop.
Save yankchina/8538162 to your computer and use it in GitHub Desktop.
prox="http://proxy.com:8080"
alias proxyon="export http_proxy=$prox && export https_proxy=$prox"
alias proxyoff='unset http_proxy && unset https_proxy'
echo "Turning http(s) proxies on"
proxyon
# investigate function is repeated here for portability but, we
# only define it if investigate isn't already a defined function
if ! type -t investigate &> /dev/null; then
function investigate {
local output_prefix='' # could be something like [*]
local output_sep=": " # could be ", " ": " etc
for varname in $@; do
echo -n "${output_prefix}${varname}${output_sep}"
v='echo $'
v="${v}$(echo $varname)"
eval $v
done
}
export -f investigate
fi
# Display the state of the proxy variables
function proxystate {
local HTTP="off"
local HTTPS="off"
local SOCKS="off"
if export | grep -q http_proxy;then
HTTP=$http_proxy
fi
if export | grep -q https_proxy;then
HTTPS=$https_proxy
fi
if export | grep -q socks_proxy;then
SOCKS=$socks_proxy
fi
echo "[*] Current state of proxy variables"
investigate HTTP HTTPS SOCKS
}
export -f proxystate
proxystate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment