Last active
March 22, 2017 02:10
-
-
Save zhouyl/9500622 to your computer and use it in GitHub Desktop.
在本机通过 ssh-tunnels 搭建 socks5 代理
This file contains hidden or 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 | |
| # Create a socks5 proxy server to use ssh-tunnels | |
| ACTION="@$1" | |
| HOST=sshproxyhost # edit /etc/hosts | |
| LISTEN=127.0.0.1:8600 | |
| LOGDIR=/var/log/ssh-proxy/`date +%Y` | |
| LOGFILE=$LOGDIR/`date +%Y%m%d`.log | |
| if [ ! -d $LOGDIR ] ; then | |
| sudo mkdir -p $LOGDIR | |
| sudo chmod -R 777 $LOGDIR | |
| fi | |
| if [ $ACTION = "@start" ] ; then | |
| echo -n "Starting SSH-Proxy Service..." | |
| PID=`ps -ef | grep "$HOST" | grep -v grep | awk '{print $2}'` | |
| if [ $PID ] ; then | |
| echo -e " \033[33;49;1m[RUNNING]\033[39;49;0m" | |
| else | |
| ssh -N -v root@$HOST -D $LISTEN > $LOGFILE 2>&1 & | |
| PID=`ps -ef | grep "$HOST" | grep -v grep | awk '{print $2}'` | |
| if [ $PID ] ; then | |
| echo -e " \033[32;49;1m[YES]\033[39;49;0m" | |
| else | |
| echo -e " \031[30;49;1m[NO]\033[39;49;0m" | |
| fi | |
| fi | |
| echo -e "\nPS Status:" | |
| ps aux | grep "$HOST" | grep -v grep | |
| elif [ $ACTION = "@stop" ] ; then | |
| echo -n "Stopping SSH-Proxy Service..." | |
| PID=`ps -ef | grep "$HOST" | grep -v grep | awk '{print $2}'` | |
| if [ $PID ] ; then | |
| kill -9 $PID | |
| echo -e " \033[32;49;1m[YES]\033[39;49;0m" | |
| else | |
| echo -e " \033[31;49;1m[NO]\033[39;49;0m" | |
| fi | |
| elif [ $ACTION = "@restart" ] ; then | |
| $0 stop | |
| $0 start | |
| elif [ $ACTION = "@status" ] ; then | |
| ps -ef | grep "$HOST" | grep -v grep | |
| elif [ $ACTION = "@log" ] ; then | |
| echo "Log Directory: $LOGDIR" | |
| ls -l $LOGDIR | |
| else | |
| echo "Usage: $0 [start|stop|restart|status|log]" | |
| echo "" | |
| echo "ps list:" | |
| ps -ef | grep "$HOST" | grep -v grep | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment