一、脚本功能
ssh动态转发远端至本地端口
二、脚本配置
USERNAME 用户
HOSTNAME 你自己主机的ip或域名
PORT 可以自定义端口 脚本默认为9000
三、脚本
proxy.sh
#!/bin/bash
#author firxiao
#ssh 端口转发
HOSTNAME=XXXX #主机名或ip
USERNAME=XXXX #用户名
PORT=9000 #本地监听端口
pid=`ps ax | grep -i $HOSTNAME | grep -v grep | awk '{print $1}'`
function start()
{
if [ -n "$pid" ];
then
{
echo "The proxy(${pid}) alreay running..."
exit 1
}
else
{
nohup /usr/bin/ssh -D $PORT $HOSTNAME -N >log.txt 2>&1 &
echo "The proxy started... OK"
}
fi
}
function stop()
{
if [ -z "$pid" ] ; then
echo "No proxy running."
exit -1;
fi
echo "The proxy(${pid}) is running..."
kill ${pid}
echo "Send shutdown request to proxy(${pid}) OK"
}
function status()
{
if [ -z "$pid" ] ; then
echo "No proxy running."
exit -1;
fi
echo "The proxy(${pid}) is running..."
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo "Useage: $0 start|stop|status"
esac
三、配置SwitchySharp
选择SOCKS v5 协议
代理地址 127.0.0.1 9000
ssh端口转发参考http://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/index.html