记录下使用woo语言开发 sockets 和https代理过程

已经在gitee开源: https://gitee.com/oshine/woo_proxy

目前使用的是一个端口监听所有的代理包含http https sockets4 sockets5

作为程序员,当克隆时候速度蚂蚁一般真的没地儿诉苦

好了废话不多说,上代码:

1.启动服务监听端口

client.woo 文件内容:

_DIR = _DIR == '.' and './' or _DIRlocal conf = require(_DIR .. '.conf')local addr = conf['http/s_sockets4/5_addr']
print('sockets(4/5) and http/s proxy start on:', addr)local ser = woo.sockets:new()-- 开启 tcp sockets proxy监听服务
ser:listen('tcp', addr, function(handler)-- 启动一个线程来处理,启动线程需要绝对路径_run(_DIR .. '/client/sockets_handler.woo', handler, _DIR, conf) -- 把sockets handler,目录位置传入线程中去
end, function(err)print(err)
end)

2.handler文件内容:

require(_ARGS[2] .. '.client.utils'); -- 导入工具包
local conf = _ARGS[3];print('sockets(4/5) handler in:')
_out('_ARGS:=== ', _ARGS);(function()-- 获取线程传入的 sockets handlerlocal handler = _ARGS[1]assert(handler, 'server form parent not correct.')print('conn ok!')local len, b = handler:read(1)if len < 1 thenprint("Request packet is too short!")returnendprint('Got first byre for proxy:', b[1])if b[1] == 0x05 then-- sockets5协议print('sockets-5 in')-- 开始读取sockets 5 剩余报文local sockets_header_read_left_len, _, err = handler:read(1024)if sockets_header_read_left_len < 1 or err thenprint('read sockets5 left header error:', err)returnend-- 回应客户端:Socks服务端不需要验证方式_, _ = handler:write({ 0x05, 0x00 })-- 读取客户端报文中的规则local sockets_header_read_len, sockets_header_bytes, err1 = handler:read()if sockets_header_read_len < 1 or err1 thenprint('read sockets5 new header error:', err)returnendlocal host, port(({ [0x01] = function()-- ip v4host = sockets_header_bytes[5] .. '.' .. sockets_header_bytes[6] .. '.' ..sockets_header_bytes[7] .. '.' .. sockets_header_bytes[8]print("got ip v4:", host)end, [0x03] = function()-- domainhost = _byte_str(_tbl_sub(sockets_header_bytes, 6, sockets_header_read_len - 1)) -- // [5] 表示域名的长度print("got domain:", host)end, [0x04] = function()-- ip v6host = _byte_str(_tbl_sub(sockets_header_bytes, 5, 20))print("got ip v6:", host)end })[sockets_header_bytes[4]])()-- got portport = math.bor(math.lshift(sockets_header_bytes[sockets_header_read_len - 1], 8),sockets_header_bytes[sockets_header_read_len])print('parse host port done:', host, port)print('======_include======', _include)local tsf = _include('client.transfer'):new({tokenB = "123321123", timeB = _time(), portB = port, remoteAddr = conf.remote_addr,hostB = host, remoteConnectOk = function()--// reply success to clientprint('reply success to client')_, _ = handler:write({ 0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })end, beforeEachCopy = nil })tsf:isValid(handler, function()print('sockets5 isValid ok!')tsf:eachCopy()end, function(err11)print('sockets5 isValid err:', err11)end)elseif b[1] == 0x04 then-- sockets4协议print('sockets-4 in')len, b = handler:read(1)--var b [1]byteif len ~= 1 thenreturn print("Socks4Request input too short")endlocal s = {}s.command = b[1]if b[1] ~= 1 thenif b[1] == 2 then-- todo 未实现绑定命令return print("Unimplemented bind command")endreturn print("Invalid command:" .. s.command)endlen, b = handler:read(2)s.port = _byte_str(b)s.port_b = (b)--address := make([]byte, 4)local ll, bb = handler:read(4)if ll ~= 4 thenreturn print("Socks4Request address is too short")ends.address = _byte_str(bb)s.address_b = (bb)-- sock4A--if s.address.String() == "0.0.0.x" then--    return errors.New("Unimplemented SOCK 4A protocol")--endlocal n, b1 = handler:read(1)if n ~= 1 thenreturn print("Socks4Request input too short")endif b1[1] ~= 0 thenreturn print("Sock4 protocol errored")end-- okprint('======_include======', _include)local tsf = _include('client.transfer'):new({tokenB = "123321123", timeB = _time(), portB = s.port, remoteAddr = conf.remote_addr,hostB = s.address, remoteConnectOk = function()local b = {}b = _merge(b, 0, 0x5A)b = _merge(b, s.port_b, s.address_b)-- b = append(b, byte((s.Port&0xFF00)>>8), byte(s.Port&0xFF))print('reply success to client')handler:write(b)end, beforeEachCopy = nil })tsf:isValid(handler, function()print('sockets5 isValid ok!')tsf:eachCopy()end, function(err11)print('sockets5 isValid err:', err11)end)else  -- if b[1] == _ascii('C')-- handler for http/sprint('===========handler for http/s============')_ARGS[4]=b_include('client.http(s)_single')end--handler:close()--print('sockets server read,len:', n, 'str:', _byte_str(b))--f:write(' hello client!')
end)()

此处列出一些主要的逻辑代码,全部代码去 gitee:https://gitee.com/oshine/woo_proxy

3.然后看设置:

windows10设置很简单,找不到这个界面,在设置主页搜索proxy(英文系统) 或者 代理(中文系统)

使用woo 语言开发 sockets4 sockets5 http https代理完整记录相关推荐

  1. 使用 Go 语言开发大型 MMORPG 游戏服务器怎么样?(非常稳定、捕获所有异常、非常适合从头开始,但大公司已经有现成的C++框架、所以不会使用)

    使用 Go 语言开发大型 MMORPG 游戏服务器怎么样?(非常稳定.捕获所有异常.非常适合从头开始,但大公司已经有现成的C++框架.所以不会使用) 参考文章: (1)使用 Go 语言开发大型 MMO ...

  2. gui窗口遮挡算法_基于 C 语言开发的 GUI 框架

    一.介绍 AWTK全称Toolkit AnyWhere,是ZLG开发的开源GUI引擎,旨在为嵌入式系统.WEB.各种小程序.手机和PC打造的通用GUI引擎,为用户提供一个功能强大.高效可靠.简单易用. ...

  3. 用 C 语言开发一门编程语言 — 字符串与文件加载

    目录 文章目录 目录 前文列表 字符串 读取字符串 注释 文件加载函数 命令行参数 打印函数 报错函数 源代码 前文列表 <用 C 语言开发一门编程语言 - 交互式解析器> <用 C ...

  4. 用 C 语言开发一门编程语言 — 语法解析器

    目录 文章目录 目录 前文列表 编程语言的本质 词法分析 语法分析 使用 MPC 解析器组合库 安装 快速入门 实现波兰表达式的语法解析 波兰表达式 正则表达式 代码实现 前文列表 <用 C 语 ...

  5. python语言编程环境-python语言开发搭建电脑环境的方法

    python语言开发搭建电脑环境的方法 发布时间:2020-08-24 15:57:58 来源:亿速云 阅读:89 作者:小新 这篇文章主要介绍了python语言开发搭建电脑环境的方法,具有一定借鉴价 ...

  6. 为什么很多公司转型Go语言开发?Go语言能做什么

    来源:http://t.cn/EXZCk88 1.为什么选择Go语言 选择Go语言的原因可能会有很多,关于Go语言的特性.优势等,我们在之前的文档中也已经介绍了很多了.但是最主要的原因,应该是基于以下 ...

  7. golang微服务框架对比_Go语言开发的微服务框架,你了解多少?

    Go语言开发的微服务框架 1.项目名称:Istio 项目简介:Istio是由Google.IBM和Lyft开源的微服务管理.保护和监控框架.使用istio可以很简单的创建具有负载均衡.服务间认证.监控 ...

  8. 使用Sublime text 3打造一个小巧但强大的Go语言开发IDE

    版权声明:欢迎转载,转载请注明出处! https://blog.csdn.net/iTaacy/article/details/76716049 使用Sublime text 3打造一个小巧但强大的G ...

  9. Dapr + .NET 实战(十三)跨语言开发

    欢迎大家参加4小时Dapr+.NET 5的实战课程 课程链接     https://ke.qq.com/course/4000292?tuin=1271860f 因为基于Dapr的服务架构是不限语言 ...

最新文章

  1. 称重管理系统如何修改重量_微嵌智能称重方案实现自动零件计数秤
  2. 调用外部文件(ShellExecute)
  3. 【解题报告】Leecode 643. 子数组最大平均数 I——Leecode 刷题系列
  4. 有意思的记录-shell(持续更新)
  5. 解决Cacti监控图像断断续续问题
  6. 小米6钉子户们的胜利!复刻机可能要来了,目前已在工程验证阶段
  7. python实现嵌套功能_我应该如何在Python中实现“嵌套”子命令?
  8. mysql5.7主从复制--在线变更复制类型【转】
  9. nginx做负载均衡+keepalived(做主备)
  10. 直播开发中关于三级分销功能源码的实现介绍
  11. 百家讲坛2001-2016年节目播出表-总目录
  12. Google Chrome谷歌浏览器清除缓存以及清除Cookie快捷键
  13. android音频服务,android-在后台服务中录制音频
  14. 儿童自行车品牌推荐全球十大儿童山地自行车品牌排行榜
  15. python开平方计算(求平方根)
  16. 【项目管理】团队绩效域管理
  17. 彩铅练习,夜色中的小鸟
  18. 硬汉内贾德:让美国人战栗(推荐)
  19. 你会微信小程序自定义底部导航栏吗?
  20. 亚马逊账户锁定无法登陆_如何删除您的亚马逊账户

热门文章

  1. 第十二届蓝桥杯初赛试题B直线
  2. 基于SSH的羽毛球场地预定系统毕业设计-运动场地预定系统 源码 java-体育馆预定场地管理系统-场馆预约系统
  3. BMP格式补充(16bbp 32bbp 4字节对齐 pixel data存放顺序)
  4. 西安10万条业主信息被贩卖
  5. 括号表示转孩子数组表示法
  6. 偶像Stallman
  7. 春天的马车曲(横光利一)
  8. 生产者与消费者模式的概念、运用、3种实现
  9. 储存quill与php,import – 在扩展Quill方面遇到问题
  10. Android音量调节的实现(RingtoneManager和RingerVolumePreference)