Transfer HTTP Proxy to Socks Pro

2018-06-24  本文已影响0人  HackerZGZ

Intro

想必编程的小伙伴经常都会因为一个问题而烦恼,那就是如何将一些不支持 Socks 协议的工具搭上梯子呢?比如我最近就因为 Docker for Mac 只有 HTTP Proxy 而烦恼,于是经过一番研究,终于成功让 HTTP Proxy 也能享受到 Socks Proxy 了,下面就来说说具体步骤。

Prerequisites

本教程有两个先决条件:

Action

Scripts

为了方便,我编写了一个简单脚本,如果有需要的同学可以拿去自行改造。

#!/bin/bash

echo "http proxy start"

OUTPUT_FILE="./http_proxy.out"
POLI_CONF_SOCKET="127.0.0.1:1086"
POLI_CONF_PROXY="$(ipconfig getifaddr en0)" # only on OSX

if [ -z $POLI_CONF_SOCKET -o -z $POLI_CONF_PROXY ]; then
    echo "[ERROR] cannot find local proxy address."
    exit -1
fi


echo 'polipo start: {"socket":"' $POLI_CONF_SOCKET '", "proxy_address":"' $POLI_CONF_PROXY '"}'


# use polipo proxy transfer socks5 protocol to http[s] protocol
nohup polipo socksParentProxy=$POLI_CONF_SOCKET proxyAddress=$POLI_CONF_PROXY >> $OUTPUT_FILE 2>&1 &

sleep 1

PID=$(ps -e | grep $! | grep -v 'grep' | awk '{ print $1 }')

if echo $PID | egrep -e '^[0-9]+$'; then
    echo "export proxy to terminal start"
    LOCAL_PROXY=$POLI_CONF_SOCKET":8123"
    export http_proxy=$LOCAL_PROXY
    echo "create sock5 to http proxy under "$LOCAL_PROXY" success!"
else
    echo "[ERROR] start proxy failed, checkout your network please"
    echo "tracing your error logs:"
    cat $OUTPUT_FILE
fi
上一篇下一篇

猜你喜欢

热点阅读