展开目录
nodejs socks5
nodejssocks5
X
陈尼玛的博客
记录开发生涯的踩坑经历,用时间来验证成长
加载中
const net=require('net')

net.createServer(c=>{
  let remote_connection=null, local_ready=null
  let close=e=>{
      console.log(e)
    c.destroy()
  }
  c.on('data', b=>{
    console.log(b)
    if(!local_ready) {
      if(b[0]===0x05) {
        local_ready=true
        c.write(Buffer.from([0x05, 0x00]))
      }else close()
    }else if(!remote_connection) {
      let host, port, n=b.length
      switch(b[3]) {
          case 0x01: // ipv4
          host=b.slice(4, 8).join('.')
          break
        case 0x03: // hostname
          host=b.slice(5, n-2).toString('utf-8')
          break
        case 0x04: //ipv6
          host=b.slice(4, 20).map(a=>a.toString(16)).map(a=>a.length<2?'0'+a:a).join(':')
          break
      }
      port=b[n-2]<<8 | b[n-1]
      remote_connection=net.createConnection(port, host)
      remote_connection.on('ready', _=>{
        c.write(Buffer.from([0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
      })
      remote_connection.on('error', close)
      remote_connection.setTimeout(3e3)
      remote_connection.on('data', b=>{
        c.write(b)
      })
      remote_connection.on('close', close)
    }else remote_connection.write(b)
  })
}).listen(9090)

curl --socks5 127.0.0.1:9090 http://github.com https://aslibra.com/blog/read.php/1808.htm

相关文档

暂无

随便看看

  1. sqlite 查看table的构建语句

  2. css多行文本超出截断显示省略号

  3. sass变量和继承类写法

  4. css3 文字渐变色

  5. npm远程服务器某些配置不兼容代理的解决办法

  6. npm包命令行调用

  7. heroku登陆cli

  8. 模拟307跳转情况

  9. 树莓派 3B/3B+ usb启动

  10. 树莓派配置wifi热点

  11. 把树莓派的存储空间拓展到整张TF卡中

  12. 树莓派配置wifi

  13. mysql选取内容导出到文件

  14. ie8上Image.onload不触发问题

  15. 随机取某个概率区间的代码

  16. bootstrap modal弹框导致ie无法获取焦点

  17. 数据库清理优化

畅言模块加载中