Skip to content

Instantly share code, notes, and snippets.

@Justsoos
Last active November 2, 2018 21:27
Show Gist options
  • Save Justsoos/0f016ad2ab6a329731b457919eb7071e to your computer and use it in GitHub Desktop.
Save Justsoos/0f016ad2ab6a329731b457919eb7071e to your computer and use it in GitHub Desktop.
obsolete: proxychains CLI wrapper
#!/bin/sh
# proxychains CLI wrapper
# Choose pre-supposed profile with -1,-2,-3, OR no param means default profile, OR appoint manually by -n proxy(Node)_ip(hostname):port and -p proxy_Protocol
# Default profile
PROXY_HOSTNAME=127.0.0.1
PROXY_PORT=1080
PROTOCOL=socks5
# profile 1
PROXY_HOSTNAME1=127.0.0.1
PROXY_PORT1=9999
PROTOCOL1=socks5
# profile 2
PROXY_HOSTNAME2=SomeProxySite.com
PROXY_PORT2=443
PROTOCOL2=https
# profile 3
PROXY_HOSTNAME3=SomeProxySite.com
PROXY_PORT3=5353
PROTOCOL3=socks5
while getopts :n:p:123 opt
do
case $opt in
1)
# profile 1
PROXY_HOSTNAME=$PROXY_HOSTNAME1
PROXY_PORT=$PROXY_PORT1
PROTOCOL=$PROTOCOL1
;;
2)
# profile 2
PROXY_HOSTNAME=$PROXY_HOSTNAME2
PROXY_PORT=$PROXY_PORT2
PROTOCOL=$PROTOCOL2
;;
3)
# profile 3
PROXY_HOSTNAME=$PROXY_HOSTNAME3
PROXY_PORT=$PROXY_PORT3
PROTOCOL=$PROTOCOL3
;;
n)
# appointed proxy hostname & port
PROXY_PORT=$(echo $OPTARG | awk -F ':' '{print $(NF)}')
# remove [] of IPv6
PROXY_HOSTNAME=$(echo $OPTARG | sed "s/:$PROXY_PORT//g" | sed "s/\[//g" | sed "s/\]//g")
;;
p)
# appointed proxy protocol
PROTOCOL=$OPTARG
;;
:)
;;
esac
done
shift "$((OPTIND-1))"
PROXY_IP=$(getent hosts $PROXY_HOSTNAME | head -n1 | cut -d " " -f1)
conf=/tmp/proxychains4.conf.$$
cat << EOF > $conf
strict_chain
proxy_dns
remote_dns_subnet 224
tcp_read_time_out 15000
tcp_connect_time_out 8000
[ProxyList]
EOF
echo "$PROTOCOL $PROXY_IP $PROXY_PORT" >> $conf
trap "rm -f $conf" INT TERM
proxychains4 -f "$conf" "$@"
ec="$?"
rm -f "$conf"
exit "$ec"
@Justsoos
Copy link
Author

Justsoos commented Nov 2, 2018

obsolete, be deleted at any time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment