內(nèi)網(wǎng)穿透工具
github: https://github.com/sazima/proxynt
原理
特性
- 隨時(shí)隨地打開(kāi)瀏覽器管理端口映射
- 公網(wǎng)服務(wù)器和內(nèi)網(wǎng)客戶端之間使用 WebSocket 加密傳輸
- 依賴少, 使用 pip一鍵安裝
- 穩(wěn)定, 自動(dòng)重連, 已在生產(chǎn)環(huán)境中使用
常用場(chǎng)景
- 在家托管網(wǎng)站服務(wù)器
- 管理物聯(lián)網(wǎng)設(shè)備
安裝
pip install proxynt
使用
客戶端
# 查看幫助
nt_client --help
# 啟動(dòng)客戶端
nt_client -c config_c.json
服務(wù)端
# 查看幫助
nt_server --help
# 啟動(dòng)服務(wù)端
nt_server -c config_s.json
服務(wù)端ui
管理頁(yè)面路徑為websocket路徑+/admin,
比如
http://192.168.9.224:18888/websocketpath/admin
示例, 通過(guò) SSH 訪問(wèn)內(nèi)網(wǎng)機(jī)器
假設(shè)公網(wǎng)機(jī)器的ip是 192.168.9.224
1. 在公網(wǎng)機(jī)器上配置config_s.json
{
"port": 18888,
"password": "helloworld",
"path": "/websocket_path",
"admin": {
"enable": true,
"admin_password": "new_password"
}
}
說(shuō)明:
-
port
: 監(jiān)聽(tīng)端口 -
password
: 連接密碼 -
path
: websocket路徑 -
admin
: 管理頁(yè)配置(非必須) -
admin.enable
: 是否啟用管理頁(yè) -
admin.admin_password
: 管理密碼
然后啟動(dòng):
nt_server -c config_s.json
2. 在需要被訪問(wèn)的內(nèi)網(wǎng)電腦上配置config_c.json
配置config_c.json
{
"server": {
"port": 18888,
"host": "192.168.9.224",
"https": false,
"password": "helloworld",
"path": "/websocket_path"
},
"client_name": "我家里的小電腦",
"client": [
{
"name": "ssh1",
"remote_port": 12222,
"local_port": 22,
"local_ip": "127.0.0.1"
}
]
}
說(shuō)明:
-
server
: 要連接的服務(wù)器端口, ip, 是否是https, 密碼, websocket路徑 -
client_name
: 客戶端名稱(chēng) -
client
: 這里是將本機(jī)的22端口映射到服務(wù)器的12222端口上
然后啟動(dòng):
nt_client -c config_c.json
3. ssh 連接:
ssh -oPort=12222 test@192.168.9.224
打開(kāi)管理頁(yè)面:
http://192.168.9.224:18888/websocketpath/admin
完整配置說(shuō)明
- 客戶端 config_c.json
{
"server": { // 要連接的服務(wù)端配置
"port": 18888, // 端口
"host": "192.168.9.224", // 端ip
"https": false, //服務(wù)端是否啟動(dòng)https
"password": "helloworld", // 密碼
"path": "/websocket_path" // websocket 路徑
},
"client": [ // 轉(zhuǎn)發(fā)的配置列表
{
"name": "ssh",
"remote_port": 1222,
"local_port": 22,
"local_ip": "127.0.0.1"
},
{
"name": "mongo",
"remote_port": 1223,
"local_port": 27017,
"local_ip": "127.0.0.1"
}
],
"client_name": "ubuntu1", // 客戶端名稱(chēng), 要唯一
"log_file": "/var/log/nt/nt.log" // 日志路徑
}
- 服務(wù)端 config_c.json
{
"port": 18888, // 監(jiān)聽(tīng)端口
"password": "helloworld", // 密碼
"path": "/websocket_path", // websocket路徑
"log_file": "/var/log/nt/nt.log", // 日志路徑
"admin": {
"enable": true, // 是否啟用管理頁(yè)
"admin_password": "new_password" // 管理頁(yè)密碼
}
}