GithubHelp home page GithubHelp logo

zanjie1999 / tcp-over-websocket Goto Github PK

View Code? Open in Web Editor NEW
270.0 4.0 47.0 1.36 MB

将TCP/UDP放到WebSocket中传输(就能走CDN)基于ws的内网穿透 隧道代理 tcp2ws 全平台0依赖

Go 91.28% Batchfile 4.31% Shell 4.41%
go websocket tcp tcp2ws proxy proxy-server proxy-client

tcp-over-websocket's Introduction

Tcp over WebSocket (TCP to WebSocket, tcp2ws)

本工具能 使用WebSocket创建隧道,实现TCP端口转发
在v6.0及以后的版本支持了wss,也就是说现在可以实现https ssl进行更安全的传输 在v8.3及以后的版本支持了ip优选,会自动选择域名解析中最优的cdn ip进行连接
在v9.0及以后的版本支持了UDP,也就是说现在可以实现UDP端口转发了
也就是UDP over WebSocket (UDP to WebSocket, udp2ws) 并没有独立成新程序,写在一起了
启动时会同时转发指定的端口的TCP和UDP流量

因为经常修改优化,所以请Star,不要Fork

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

举个例子,一个服务器只能通过cdn的http转发(或者https),它也不能联网,这时你就可以利用此工具将需要转发的端口(比如22)转换成ws协议(http)来传输,再去Nginx里面配一个反向代理,那么当本客户端访问Nginx提供的服务的特定路径时将反代到本服务端,实现内网穿透进行端口转发
当然Nginx不是必须的,直接把监听端口开放到公网上也行 这时防火墙仅仅发现你连接了一个WebSocket而已 并且在网络不稳定时,断开的ws会自动重连,保持着转发的tcp连接(断开ws超过2分钟tcp连接将被断开)

似乎有别的工具也能实类似的功能,写它干嘛?

最初为了实现将ssh用Nginx转发,写的时候还没找到这种工具,所以先实现了tcp放到ws中传输,但像Nginx就算是ws长链接,根据官方文档描述,连接超时时间无论配置多大,通常都不能连接超过75秒,时间一到ssh就会断,于是实现了重连和重发,这是别的工具没有的
这个工具也不会有太多花里胡哨的功能,干好它的本职工作

那为什么要支持UDP呢?

UDP是不可靠的,所以在传输过程中可能会丢包,但是这个工具会自动重传丢失的数据包
例如用做Dns转发,WebSocket会在客户端发送UDP数据包时才创建连接,并且在2分钟超时后自动断开,既保证了连接稳定性,又不会一直挂着连接占用资源

如何使用

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

另外也可以使用wss(https ssl)协议,ssl更为安全,但需要消耗更多流量,需要指定证书路径,另外顺带提一下nginx可以把wss(https)转发到ws(http)
服务端:
tcp2ws 要代理的ip:端口 本ws服务的监听端口 证书.crt 证书.key tcp2ws 本地端口 本ws服务的监听端口 证书.crt 证书.key
tcp2ws 本地端口 监听ip:本ws服务的监听端口 证书.crt 证书.key
使用默认的文件名 server.crt server.key(这里的wss也可以是httpsssl
tcp2ws 要代理的ip:端口 本ws服务的监听端口 wss
客户端:
tcp2ws wss://链接 本地监听端口
tcp2ws https://链接 本地监听端口

生成自签证书的方法(一路回车即可):

openssl genrsa -out server.key 2048
openssl ecparam -genkey -name secp384r1 -out server.key
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 36500

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

还可以写一个死循环来守护运行 while true;do;tcp2ws 127.0.0.1:22 127.0.0.1:22222;done
或者用screen来后台运行
screen -dmS tcp2ws bash -c "tcp2ws 127.0.0.1:22 127.0.0.1:22222"

速度

在乞丐版M1 Pro的macOS下使用本工具来回转换iperf3端口测试得到的数据

[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec   988 MBytes  8.28 Gbits/sec
[  5]   1.00-2.00   sec   977 MBytes  8.19 Gbits/sec
[  5]   2.00-3.00   sec   982 MBytes  8.23 Gbits/sec
[  5]   3.00-4.00   sec   994 MBytes  8.34 Gbits/sec
[  5]   4.00-5.00   sec   966 MBytes  8.10 Gbits/sec
[  5]   5.00-6.00   sec   982 MBytes  8.24 Gbits/sec
[  5]   6.00-7.00   sec   989 MBytes  8.30 Gbits/sec
[  5]   7.00-8.00   sec   935 MBytes  7.84 Gbits/sec
[  5]   8.00-9.00   sec  1004 MBytes  8.42 Gbits/sec
[  5]   9.00-10.00  sec   984 MBytes  8.26 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-10.00  sec  9.57 GBytes  8.22 Gbits/sec                  sender
[  5]   0.00-10.00  sec  9.56 GBytes  8.21 Gbits/sec                  receiver

走wss,因为ssl,速度肉眼可见下降:

[ ID] Interval           Transfer     Bitrate
[  5]   0.00-10.00  sec  7.38 GBytes  6.34 Gbits/sec                  sender
[  5]   0.00-10.00  sec  7.38 GBytes  6.33 Gbits/sec                  receiver

直连

[ ID] Interval           Transfer     Bitrate
[  5]   0.00-10.00  sec   119 GBytes   102 Gbits/sec                  sender
[  5]   0.00-10.00  sec   119 GBytes   102 Gbits/sec                  receiver

在i7-8550u的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

伪装

在直接访问监听端口的任意路径,默认会返回一个空白页面
可以写一个index.html放到运行目录下来代替这个空白页面 直接访问时就会显示这个文件的内容,伪装成一个非常普通的Web服务
推荐用一个叫SingleFile的插件可以把页面直接存成一个文件

tcp-over-websocket's People

Contributors

zanjie1999 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tcp-over-websocket's Issues

【建议】多个地址代理和增加config文件

如果可以同时添加多个代理,通过读取config文件来管理是不是会更好,比如tcp2ws -config.cfg
config文件里就一行一个代理,或者说定义一些.crt和.key文件的路径,我想这样会不会更好。每次重启都打这一长串........

ip故障时不会重新解析

目前使用一段时间后发现只会在启动的时候解析ip,后面即便ip无法连接或者dns记录更新也不会做任何变动。对于基于DNS调度的CDN很不友好(目前除了cloudflare和fastly,其他CDN厂商基本都是DNS调度,ip经常可能会出现上下架或者故障切换等情况)
建议做一下改动:
1、记录解析的ttl,作为ip有效期,本次tcp断开之后重新查询dns记录,获取新ip
2、ip解析失败3次以上,重新查询ip地址

一直在复用已关闭的连接

在日志里面发现进程一直在复用关闭的连接,导致一直连接不上,除非重启进程

Oct 12 11:32:16 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:16 0c731 ws write err: use of closed network connection
Oct 12 11:32:16 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:16 0c731 ws -> tcp Boom!
Oct 12 11:32:16 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:17 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:17 0c731 ws -> tcp Boom!
Oct 12 11:32:17 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:17 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:17 0c731 ws -> tcp Boom!
Oct 12 11:32:17 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:17 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:17 0c731 ws -> tcp Boom!
Oct 12 11:32:17 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:17 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:17 0c731 ws write err: use of closed network connection
Oct 12 11:32:18 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:18 0c731 ws -> tcp Boom!
Oct 12 11:32:18 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:18 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:18 0c731 ws -> tcp Boom!
Oct 12 11:32:18 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:18 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:18 0c731 ws -> tcp Boom!
Oct 12 11:32:18 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:18 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:18 0c731 ws -> tcp Boom!
Oct 12 11:32:18 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:19 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:19 0c731 ws -> tcp Boom!
Oct 12 11:32:19 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:19 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:19 0c731 ws write err: use of closed network connection
Oct 12 11:32:19 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:19 0c731 ws -> tcp Boom!
Oct 12 11:32:19 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:19 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:19 0c731 ws -> tcp Boom!
Oct 12 11:32:19 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:19 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:19 0c731 ws -> tcp Boom!
Oct 12 11:32:19 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:20 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:20 0c731 ws -> tcp Boom!
Oct 12 11:32:20 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:20 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:20 0c731 ws write err: use of closed network connection
Oct 12 11:32:20 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:20 0c731 ws -> tcp Boom!
Oct 12 11:32:20 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:20 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:20 0c731 ws -> tcp Boom!
Oct 12 11:32:20 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:20 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:20 0c731 ws -> tcp Boom!
Oct 12 11:32:20 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:21 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:21 0c731 ws -> tcp Boom!
Oct 12 11:32:21 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:21 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:21 0c731 ws write err: use of closed network connection
Oct 12 11:32:21 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:21 0c731 ws -> tcp Boom!
Oct 12 11:32:21 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:21 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:21 0c731 ws -> tcp Boom!
Oct 12 11:32:21 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:21 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:21 0c731 ws -> tcp Boom!
Oct 12 11:32:21 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:22 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:22 0c731 ws -> tcp Boom!
Oct 12 11:32:22 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:22 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:22 0c731 ws -> tcp Boom!
Oct 12 11:32:22 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:22 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:22 0c731 ws write err: use of closed network connection
Oct 12 11:32:22 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:22 0c731 ws -> tcp Boom!
Oct 12 11:32:22 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:22 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:22 0c731 ws -> tcp Boom!
Oct 12 11:32:22 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:23 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:23 0c731 ws -> tcp Boom!
Oct 12 11:32:23 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:23 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:23 0c731 ws -> tcp Boom!
Oct 12 11:32:23 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:23 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:23 0c731 ws write err: use of closed network connection
Oct 12 11:32:23 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:23 0c731 ws -> tcp Boom!
Oct 12 11:32:23 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:23 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:23 0c731 ws -> tcp Boom!
Oct 12 11:32:23 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:24 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:24 0c731 ws -> tcp Boom!
Oct 12 11:32:24 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:24 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:24 0c731 ws -> tcp Boom!
Oct 12 11:32:24 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:24 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:24 0c731 ws -> tcp Boom!
Oct 12 11:32:24 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:24 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:24 0c731 ws write err: use of closed network connection
Oct 12 11:32:24 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:24 0c731 ws -> tcp Boom!
Oct 12 11:32:24 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:25 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:25 0c731 ws -> tcp Boom!
Oct 12 11:32:25 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:25 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:25 0c731 ws -> tcp Boom!
Oct 12 11:32:25 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:25 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:25 0c731 ws -> tcp Boom!
Oct 12 11:32:25 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:25 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:25 0c731 ws write err: use of closed network connection
Oct 12 11:32:25 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:25 0c731 ws -> tcp Boom!
Oct 12 11:32:25 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:26 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:26 0c731 ws -> tcp Boom!
Oct 12 11:32:26 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:26 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:26 0c731 ws -> tcp Boom!
Oct 12 11:32:26 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:26 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:26 0c731 ws -> tcp Boom!
Oct 12 11:32:26 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:26 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:26 0c731 ws write err: use of closed network connection
Oct 12 11:32:27 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:27 0c731 ws -> tcp Boom!
Oct 12 11:32:27 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:27 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:27 0c731 ws -> tcp Boom!
Oct 12 11:32:27 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:27 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:27 0c731 ws -> tcp Boom!
Oct 12 11:32:27 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:27 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:27 0c731 ws -> tcp Boom!
Oct 12 11:32:27 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:28 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:28 0c731 ws write err: use of closed network connection
Oct 12 11:32:28 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:28 0c731 ws -> tcp Boom!
Oct 12 11:32:28 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:28 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:28 0c731 ws -> tcp Boom!
Oct 12 11:32:28 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:28 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:28 0c731 ws -> tcp Boom!
Oct 12 11:32:28 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:28 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:28 0c731 ws -> tcp Boom!
Oct 12 11:32:28 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:29 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:29 0c731 ws write err: use of closed network connection
Oct 12 11:32:29 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:29 0c731 ws -> tcp Boom!
Oct 12 11:32:29 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:29 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:29 0c731 ws -> tcp Boom!
Oct 12 11:32:29 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection
Oct 12 11:32:29 af-za-gp-oracle-287 config.conf[93779]: 2023/10/12 11:32:29 0c731 ws -> tcp Boom!
Oct 12 11:32:29 af-za-gp-oracle-287 config.conf[93779]: repeated read on failed websocket connection

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和client功能,让工具适应更广泛的场景

内网地址不能通过公网ip或者域名代理的情况下,你这个工具不适用;比如如下场景:
在家里电脑上启动一个网站服务为localhost:3000, 现在有一个公网服务器xxx.xxx.xxx.xxx,如何使用本工具使得互联网用户能通过xxx.xxx.xxx.xxx来访问到这个站点?
所以我建议可以有一个ws server来专门做中继,然后在访问端和被代理端分别开客户端来进行连通:

f6b94dec2e13960d2ec60a8ef023f5d

最新版改过之后还是有BUG,客户端会频繁的中断重连

客户端日志:

2023/10/04 09:18:02 447ed bye
2023/10/04 09:18:03 new tcp conn:
2023/10/04 09:18:03 dial 8abf1
2023/10/04 09:18:27 8abf1 bye
2023/10/04 09:18:28 new tcp conn:
2023/10/04 09:18:28 dial 1a85c
2023/10/04 09:22:34 1a85c bye

服务端日志:

2023/10/04 09:18:02 447ed say bye
2023/10/04 09:18:03 new ws conn: 183.230.37.181
2023/10/04 09:18:03 new tcp for 8abf1
2023/10/04 09:18:27 8abf1 say bye
2023/10/04 09:18:29 new ws conn: 183.230.37.181
2023/10/04 09:18:29 new tcp for 1a85c
2023/10/04 09:22:34 1a85c say bye

我用自己的打包(仅仅去掉NetDial: meDial参数)的客户端就没问题

dialNewWs里给ws加上头部host是不是就可以用cloudflare回退源优选ip了?

func dialNewWs(uuid string) bool {
    log.Print("dial ", uuid)

    // 构建 WebSocket 握手请求的 HTTP 头部
    headers := http.Header{}
    headers.Add("Host", "example.com") // 指定请求的域名

    dialer := websocket.Dialer{
        TLSClientConfig: &tls.Config{RootCAs: nil, InsecureSkipVerify: true},
        Proxy:          http.ProxyFromEnvironment,
        NetDial:        meDial,
    }

    // 使用自定义 HTTP 头部执行 WebSocket 握手
    wsConn, _, err := dialer.Dial(wsAddr, headers)
    if err != nil {
        log.Print("connect to ws err: ", err)
        return false
    }

    // 发送 uuid 和其他操作
    // ...

    return true
}

请问支持代理么?

因为我的机子上网需要通过squid代理的,没有办法使用全局变量HTTP_PROXY,请问该怎么办呢?

CDN优选IP需求

现在的是靠dns去解析得到IP,这个IP不一定适合自己网络使用。比如CF,优选针对自己的网络好用的IP。

现在尝试hosts文件内添加强制解析,但还是调用53端口去解析。

可否做个参数 如以下

tcp2ws ws://1.1.1.1:端口 使用的域名 监听端口

1.1.1.1代表优选ip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.