Advertisement
Guest User

proxy on function

a guest
Jan 14th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.22 KB | None | 0 0
  1. function proxy_on() {
  2.     export no_proxy="localhost,127.0.0.0/8"
  3.  
  4.     if (( $# > 0 )); then
  5.         valid=$(echo $@ | sed -n 's/\([0-9]\{1,3\}.\)\{4\}:\([0-9]\+\)/&/p')
  6.         if [[ $valid != $@ ]]; then
  7.             >&2 echo "Invalid address"
  8.             return 1
  9.         fi
  10.  
  11.         export http_proxy="http://$1/"
  12.         export https_proxy=$http_proxy
  13.         export ftp_proxy=$http_proxy
  14.         export rsync_proxy=$http_proxy
  15.         echo "Proxy environment variable set."
  16.         return 0
  17.     fi
  18.  
  19.     echo -n "username: "; read username
  20.     if [[ $username != "" ]]; then
  21.         echo -n "password: "
  22.         read -es password
  23.         local pre="$username:$password@"
  24.     fi
  25.  
  26.     echo -n "server: "; read server
  27.     echo -n "port: "; read port
  28.     export http_proxy="http://$pre$server:$port/"
  29.     export https_proxy=$http_proxy
  30.     export ftp_proxy=$http_proxy
  31.     export rsync_proxy=$http_proxy
  32.     export HTTP_PROXY=$http_proxy
  33.     export HTTPS_PROXY=$http_proxy
  34.     export FTP_PROXY=$http_proxy
  35.     export RSYNC_PROXY=$http_proxy
  36. }
  37.  
  38. function proxy_off(){
  39.     unset http_proxy
  40.     unset https_proxy
  41.     unset ftp_proxy
  42.     unset rsync_proxy
  43.     echo -e "Proxy environment variable removed."
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement