将TCP放到WebSocket中传输(就能走CDN)基于ws的内网穿透 隧道代理 tcp2ws

Tcp over WebSocket (TCP to WebSocket)

本工具能 使用WebSocket创建隧道,实现TCP端口转发

至于这样脱裤子放屁的操作有什么用?

举个例子,一个服务器只能通过cdn的http转发,它也不能联网,这时你就可以利用此工具将需要转发的端口(比如22)转换成ws协议(http)来传输,再去Nginx里面配一个反代,那么当本客户端访问Nginx提供的服务的特定路径时将反代到本服务端,实现内网穿透进行端口转发
这时防火墙仅仅发现你连接了一个WebSocket而已

如何使用

在右边Releases中选择你使用的平台的程序来运行
服务端:tcp2ws 要代理的ip:端口 本ws服务的监听端口
客户端:tcp2ws ws://链接 本地监听端口

举个 🌰
在服务器运行tcp2ws 127.0.0.1:22 22222
然后在nginx中反代了一下
在客户端运行ws://yourdomain.com/ssh 222
那么就可以通过客户端的222来访问服务器的ssh啦
是不是特别棒呢

速度

在Windows使用本工具来回转换iperf3端口测试得到的数据

[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-1.00   sec   300 MBytes  2.52 Gbits/sec
[  4]   1.00-2.00   sec   336 MBytes  2.81 Gbits/sec
[  4]   2.00-3.00   sec   320 MBytes  2.68 Gbits/sec
[  4]   3.00-4.00   sec   317 MBytes  2.66 Gbits/sec
[  4]   4.00-5.00   sec   302 MBytes  2.53 Gbits/sec
[  4]   5.00-6.00   sec   328 MBytes  2.75 Gbits/sec
[  4]   6.00-7.00   sec   312 MBytes  2.61 Gbits/sec
[  4]   7.00-8.00   sec   319 MBytes  2.67 Gbits/sec
[  4]   8.00-9.00   sec   322 MBytes  2.70 Gbits/sec
[  4]   9.00-10.00  sec   348 MBytes  2.92 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-10.00  sec  3.14 GBytes  2.70 Gbits/sec                  sender
[  4]   0.00-10.00  sec  3.13 GBytes  2.69 Gbits/sec                  receiver

两个iperf3直连

[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-10.00  sec  9.53 GBytes  8.19 Gbits/sec                  sender
[  4]   0.00-10.00  sec  9.53 GBytes  8.19 Gbits/sec                  receiver
Owner
Sparkle
Java、Python、JavaScript、Kotlin、C++、Go、C#開発者、 勉強するの初春ちゃん
Sparkle
Similar Resources
Comments
  • WINDOWS连接成功后关闭连接服务出错

    WINDOWS连接成功后关闭连接服务出错

    2021/12/12 20:31:57 new tcp conn: 2021/12/12 20:31:57 dial ws 9e90 2021/12/12 20:32:21 9e90 tcp read err: read tcp 127.0.0.1:14406->127.0.0.1:4489: wsarecv: An existing connection was forcibly closed by the remote host. 2021/12/12 20:32:21 say bye to 9e90 fatal error: concurrent map read and map write

    goroutine 9 [running]: runtime.throw({0xe853f0, 0xc0000563c0}) /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1198 +0x76 fp=0xc00004fe40 sp=0xc00004fe10 pc=0xc26416 runtime.mapaccess1_faststr(0xc000096000, 0xc000164000, {0xc0000b82c0, 0x4}) /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/map_faststr.go:21 +0x3a5 fp=0xc00004fea8 sp=0xc00004fe40 pc=0xc024e5 main.ReadWs2Tcp({0xc0000b82c0, 0x4}) /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:117 +0x43a fp=0xc00004ff90 sp=0xc00004fea8 pc=0xe12aba main.ReadWs2TcpClient({0xc0000b82c0, 0x4}) /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:153 +0x25 fp=0xc00004ffc0 sp=0xc00004ff90 pc=0xe12c25 main.RunClient·dwrap·3() /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:260 +0x2a fp=0xc00004ffe0 sp=0xc00004ffc0 pc=0xe1388a runtime.goexit() /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0xc53481 created by main.RunClient /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:260 +0x3d8

    goroutine 1 [chan receive]: main.main() /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:362 +0x6f1

    goroutine 6 [IO wait]: internal/poll.runtime_pollWait(0x244e4966708, 0x72) /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/netpoll.go:229 +0x89 internal/poll.(*pollDesc).wait(0xc000090160, 0xbfced4, 0x0) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc00007f418, 0xc000063c98) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(*FD).acceptOne(0xc00007f400, 0x1a8, {0xc0000860f0, 0xc000148000, 0xc000063d20}, 0xc4fd5b) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_windows.go:810 +0x6d internal/poll.(*FD).Accept(0xc00007f400, 0xc000063e70) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_windows.go:844 +0x1d6 net.(*netFD).accept(0xc00007f400) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/fd_windows.go:139 +0x65 net.(*TCPListener).accept(0xc000004120) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/tcpsock_posix.go:140 +0x28 net.(*TCPListener).Accept(0xc000004120) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/tcpsock.go:262 +0x3d main.tcpHandler({0xedbf10, 0xc000004120}) /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:295 +0x5e created by main.main /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:344 +0x2c5

    goroutine 7 [syscall]: os/signal.signal_recv() /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/sigqueue.go:169 +0x98 os/signal.loop() /opt/homebrew/Cellar/go/1.17.2/libexec/src/os/signal/signal_unix.go:24 +0x19 created by os/signal.Notify.func1.1 /opt/homebrew/Cellar/go/1.17.2/libexec/src/os/signal/signal.go:151 +0x2c

  • server模式启动,location后面的地址能否是自动生成的随机32位字符?

    server模式启动,location后面的地址能否是自动生成的随机32位字符?

    2022/12/17 01:25:02 Server Started ws://0.0.0.0:50022 -> 127.0.0.1:22 Proxy with Nginx: location /Pz3LRoFCiCKe9zXpOJGpvkuhS1qjCC22/ { proxy_pass http://0.0.0.0:50022/; proxy_read_timeout 3600; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-Forwarded-For $remote_addr; access_log off; }

  • server模式启动时,能否自动探测内网地址,方便ws反代用在容器环境时

    server模式启动时,能否自动探测内网地址,方便ws反代用在容器环境时

    ./tcp2ws 22 50022

    Proxy with Nginx: location /ws/ { proxy_pass http://192.168.1.2:50022/; proxy_read_timeout 3600; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-Forwarded-For $remote_addr; access_log off; }