我正在尝试找到一种方法来创建动态SSH隧道来发送HTTP请求(node.js - > SSH服务器 - >互联网)但是似乎没有任何nodeJS SSH库允许您创建动态隧道。
https://www.npmjs.com/package/tunnel-ssh似乎只允许您创建非动态隧道。
我怎么解决这个问题?感谢。
答案 0 :(得分:0)
假设您指的是SOCKS代理,ssh2
模块自述文件包含使用socksv5
模块的示例:
var socks = require('socksv5'),
Client = require('ssh2').Client;
var ssh_config = {
host: '192.168.100.1',
port: 22,
username: 'nodejs',
password: 'rules'
};
socks.createServer(function(info, accept, deny) {
// NOTE: you could just use one ssh2 client connection for all forwards, but
// you could run into server-imposed limits if you have too many forwards open
// at any given time
var conn = new Client();
conn.on('ready', function() {
conn.forwardOut(info.srcAddr,
info.srcPort,
info.dstAddr,
info.dstPort,
function(err, stream) {
if (err) {
conn.end();
return deny();
}
var clientSocket;
if (clientSocket = accept(true)) {
stream.pipe(clientSocket).pipe(stream).on('close', function() {
conn.end();
});
} else
conn.end();
});
}).on('error', function(err) {
deny();
}).connect(ssh_config);
}).listen(1080, 'localhost', function() {
console.log('SOCKSv5 proxy server started on port 1080');
}).useAuth(socks.auth.None());
// test with cURL:
// curl -i --socks5 localhost:1080 google.com