基于python实现的内网穿透工具开源

发布于:2022-10-30 ⋅ 阅读:(501) ⋅ 点赞:(0)

内网穿透工具

原理

在这里插入图片描述

该工具的公网和内网通信使用WebSocket, 因此可以部署在nginx后端服务路径上.

该工具用到的第三方库有: tornado, websocket-client, typing_extensions

使用前

git clone https://github.com/sazima/nat_traversal.git
cd nat_traversal

安装依赖

pip install -r requirements.txt

使用

客户端

python run_client.py -c config_c.json

服务端

python run_server.py -c config_s.json

示例, 通过 SSH 访问内网机器

假设公网机器的ip是 192.168.9.224

1. 在公网机器上配置config_s.json, 设置连接密码, 接受客户端配置的端口和websocket路径

{
  "port": 18888,
  "password": "yourhelloworld",
  "path": "/websocket_path"
}

然后启动:
python run_server.py -c config_s.json

2. 在需要被访问的内网电脑上配置config_c.json

配置config_c.json

{
  "server": {
    "port": 18888,
    "host": "192.168.9.224",
    "https": false,
    "password": "yourhelloworld",
    "path": "/websocket_path"
  },
  "client": [
    {
      "name": "ssh1",
      "remote_port": 12222,
      "local_port": 22,
      "local_ip": "127.0.0.1"
    }
  ]
}

然后启动:
python run_client.py -c config_c.json

3. ssh 连接:

ssh -oPort=12222 test@192.168.9.224
本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到