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
相关文档
暂无
随便看看
畅言模块加载中