增加README文档和启动脚本

This commit is contained in:
lwch
2021-08-12 17:50:41 +08:00
parent 0f4c63f82d
commit d05e426ccc
4 changed files with 265 additions and 2 deletions
+34 -1
View File
@@ -1,3 +1,36 @@
# natpass
内网穿透工具
内网穿透工具
## 实现原理
基于tls链接,server端转发流量
## 编译
CGO_ENABLED=0 go build -o bin/np-svr code/server/*.go
CGO_ENABLED=0 go build -o bin/np-cli code/client/*.go
## 配置
server端配置如下:
listen: 6154 # 监听端口号
secret: 0123456789 # 预共享密钥
tls:
key: /dir/to/tls/key/file # tls密钥
crt: /dir/to/tls/crt/file # tls证书
client端配置如下:
id: this # 客户端ID
server: 127.0.0.1:6154 # 服务器地址
secret: 0123456789 # 预共享密钥
tunnel: # 远端tunnel列表可为空
- name: rdp # 链路名称
target: that # 目标客户端ID
type: tcp # 连接类型tcp或udp
local_addr: 0.0.0.0 # 本地监听地址
local_port: 3389 # 本地监听端口号
remote_addr: 127.0.0.1 # 目标客户端连接地址
remote_port: 3389 # 目标客户端连接端口号
+1 -1
View File
@@ -1,7 +1,7 @@
id: this # 客户端ID
server: 127.0.0.1:6154 # 服务器地址
secret: 0123456789 # 预共享密钥
tunnel:
tunnel: # 远端tunnel列表可为空
- name: rdp # 链路名称
target: that # 目标客户端ID
type: tcp # 连接类型tcp或udp
+115
View File
@@ -0,0 +1,115 @@
#!/bin/sh
#
# chkconfig: 2345 12 88
# description: natpass client
### BEGIN INIT INFO
# Provides: lwch748@gmail.com
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: np-cli
# Description: natpass client
### END INIT INFO
NAME=np-cli
WORKDIR=/opt/natpass
DAEMON=/opt/natpass/bin/$NAME
CONFIG=/opt/natpass/conf/client.yaml
PIDFILE=/var/run/$NAME.pid
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting $NAME "
cd $WORKDIR
nohup $DAEMON -d -pid $PIDFILE -u nobody -conf $CONFIG > /dev/null 2>&1 &
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $PIDFILE
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down $NAME "
if [ ! -r $PIDFILE ] ; then
echo "warning, no pid file found - $NAME is not running ?"
exit 1
fi
kill -QUIT `cat $PIDFILE`
wait_for_pid removed $PIDFILE
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
status)
if [ ! -r $PIDFILE ] ; then
echo "$NAME is stopped"
exit 0
fi
PID=`cat $PIDFILE`
if ps -p $PID | grep -q $PID; then
echo "$NAME (pid $PID) is running..."
else
echo "$NAME dead but pid file exists"
fi
;;
force-quit)
echo -n "Terminating $NAME "
if [ ! -r $PIDFILE ] ; then
echo "warning, no pid file found - $NAME is not running ?"
exit 1
fi
kill -TERM `cat $PIDFILE`
wait_for_pid removed $PIDFILE
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|status|force-quit|restart}"
exit 1
;;
esac
exit $?
+115
View File
@@ -0,0 +1,115 @@
#!/bin/sh
#
# chkconfig: 2345 12 88
# description: natpass server
### BEGIN INIT INFO
# Provides: lwch748@gmail.com
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: np-svr
# Description: natpass server
### END INIT INFO
NAME=np-svr
WORKDIR=/opt/natpass
DAEMON=/opt/natpass/bin/$NAME
CONFIG=/opt/natpass/conf/server.yaml
PIDFILE=/var/run/$NAME.pid
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting $NAME "
cd $WORKDIR
nohup $DAEMON -d -pid $PIDFILE -u nobody -conf $CONFIG > /dev/null 2>&1 &
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $PIDFILE
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down $NAME "
if [ ! -r $PIDFILE ] ; then
echo "warning, no pid file found - $NAME is not running ?"
exit 1
fi
kill -QUIT `cat $PIDFILE`
wait_for_pid removed $PIDFILE
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
status)
if [ ! -r $PIDFILE ] ; then
echo "$NAME is stopped"
exit 0
fi
PID=`cat $PIDFILE`
if ps -p $PID | grep -q $PID; then
echo "$NAME (pid $PID) is running..."
else
echo "$NAME dead but pid file exists"
fi
;;
force-quit)
echo -n "Terminating $NAME "
if [ ! -r $PIDFILE ] ; then
echo "warning, no pid file found - $NAME is not running ?"
exit 1
fi
kill -TERM `cat $PIDFILE`
wait_for_pid removed $PIDFILE
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|status|force-quit|restart}"
exit 1
;;
esac
exit $?