Skip to content

Instantly share code, notes, and snippets.

@Odyno

Odyno/set-proxy.sh

Created Mar 4, 2017
Embed
What would you like to do?
Temporarily set the proxy in linux shell
odyssey@Itaca:/opt/bin/tmp$ cat set-proxy.sh
#!/bin/bash
#
# Copyright 2012 Alessandro Staniscia (email : alessandro@staniscia.net)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Contributors: Alessandro Staniscia
# Stable tag: 0.1.1
# License: GPLv2
# License URI: http://www.gnu.org/licenses/gpl-2.0.html
# URI: https://www.staniscia.net
#
# Description:
# Temporarily set the proxy in linux shell
PROXY_DEFAULT_NAME="proxydmz.trs.it"
PROXY_DEFAULT_PORT="3128"
PROXY_DEFAULT_USER="staniscia"
read -e -i "$PROXY_DEFAULT_NAME" -p "Please enter proxy hostname: " input
proxy_hostname="${input:-$PROXY_DEFAULT_NAME}"
read -e -i "$PROXY_DEFAULT_PORT" -p "Please enter proxy port: " input
proxy_port="${input:-$PROXY_DEFAULT_PORT}"
read -e -i "$PROXY_DEFAULT_USER" -p "Please enter username: " input
user="${input:-$PROXY_DEFAULT_USER}"
echo -n "Please enter password:"
stty -echo
read pwdr
stty echo
echo ""
export PROXYHOST="$user:$pwdr@$proxy_hostname:$proxy_port"
export http_proxy="http://$PROXYHOST"
export https_proxy="https://$PROXYHOST"
export ftp_proxy="ftp://$PROXYHOST"
export ftps_proxy="ftps://$PROXYHOST"
export proxy_user=$user
export proxy_passwd=$pwdr
echo "Hello $user, that's all!"
/bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.