Created
April 12, 2019 17:00
-
-
Save viniciusdaniel/2ecdf07f85ba72141821b73c6dde8415 to your computer and use it in GitHub Desktop.
proxy http over proxy socks
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
#!/bin/bash | |
logFlogPath=/tmp/polipo.log; | |
cachePath=/tmp/polipo_cache; | |
socksPort=8123; | |
httpPort=8124; | |
proxyHost=127.0.0.1; | |
gatewayServer=10.0.0.1; | |
# Catch ctrl + c and close all stuff | |
trap ctrl_c INT; | |
function ctrl_c() { | |
socks_closed=`ps aux | grep ssh | grep $socksPort | grep -v grep | sed -e 's/ */ /g' | cut -d ' ' -f 2`; | |
polipo_closed=`ps aux | grep polipo | grep -v grep | sed -e 's/ */ /g' | cut -d ' ' -f 2`; | |
for pid in {$socks_closed,$polipo_closed}; do | |
sudo kill -9 $pid 2>&1 | tee $logFlogPath; | |
done | |
} | |
polipo_path=`which polipo`; | |
if [ -z "$polipo_path" ] ; then | |
echo "You must install \"polipo\" proxy before using this command..." | tee $logFlogPath; | |
echo -e "To install run this:\n\n\tsudo apt-get install --assume-yes --no-install-recommends polipo\n\n" | tee $logFlogPath; | |
exit 1; | |
fi | |
socks_closed=`ps aux | grep ssh | grep $socksPort | grep -v grep | sed -e 's/ */ /g' | cut -d ' ' -f 2`; | |
if [ -n "$socks_closed" ]; then | |
echo "This process requires sudo"; | |
sudo kill -9 $socks_closed; | |
fi | |
echo "This process requires sudo to create socks proxy from GATEWAY"; | |
sudo ssh -o TCPKeepAlive=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=10 -D $socksPort -f -C -q -N $gatewayServer; | |
polipo_closed=`ps aux | grep polipo | grep $socksPort | grep -v grep | sed -e 's/ */ /g' | cut -d ' ' -f 2`; | |
if [ -n "$polipo_closed" ]; then | |
sudo kill -9 $polipo_closed; | |
fi | |
echo "Starting polipo proxy..." ; | |
rm -rf $cachePath; | |
mkdir -p $cachePath; | |
polipo socksParentProxy="${proxyHost}:${socksPort}" socksProxyType="socks5" proxyAddress="::0" proxyPort="${httpPort}" logSyslog="false" logFile="${logFlogPath}" diskCacheRoot="${cachePath}" & | |
proxyIP=$(echo $(ip a | grep 'inet 10.') | cut -d ' ' -f 2 | cut -d '/' -f 1); | |
echo -e "Proxy is up!\nUse this ENV Setup:\n\n\tHTTP_PROXY=\"http://${proxyIP}:${httpPort}\"\n\n####### Tail Log ########" > $logFlogPath; | |
tail -f $logFlogPath; | |
ctrl_c; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment