autossh/demo.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-04-07 19:22:13 -06:00
'use strict';
const autossh = require('./index.js');
2016-04-08 14:35:23 -06:00
// open 5 ssh tunnels
2016-04-08 21:51:03 -06:00
// for (let i = 0; i < 5; i++) {
2016-04-08 14:35:23 -06:00
2016-04-08 14:28:58 -06:00
// set up config
autossh({
2016-04-19 20:21:30 -06:00
host: 'xyz.xy.xyz.yz', // enter host address
username: 'root', // enter username
2016-04-08 14:28:58 -06:00
localPort: 'auto', // 'auto' or port number
remotePort: 5432
})
// listen for errors
.on('error', err => {
console.error('ERROR: ', err);
})
// listen for connection
.on('connect', connection => {
console.log('\n**connected**');
console.log('localPort: \t' + connection.localPort);
console.log('pid: \t\t' + connection.pid);
console.log(`tunnel established from localhost:${connection.localPort} to ${connection.host}:${connection.remotePort} as ${connection.username}`);
});
2016-04-08 14:35:23 -06:00
2016-04-08 21:51:03 -06:00
// }
2016-04-07 19:22:13 -06:00
2016-04-08 14:28:58 -06:00
/* Possible output example (localPort results are be random)
2016-04-07 19:22:13 -06:00
2016-04-08 14:28:58 -06:00
**connected**
localPort: 39570
pid: 7477
2016-04-08 14:36:10 -06:00
tunnel established from localhost:39570 to xyz.xy.xyz.yz:5432 as root
2016-04-08 14:28:58 -06:00
**connected**
localPort: 53139
pid: 7478
2016-04-08 14:36:10 -06:00
tunnel established from localhost:53139 to xyz.xy.xyz.yz:5432 as root
2016-04-08 14:28:58 -06:00
**connected**
localPort: 56421
pid: 7479
2016-04-08 14:36:10 -06:00
tunnel established from localhost:56421 to xyz.xy.xyz.yz:5432 as root
2016-04-08 14:28:58 -06:00
**connected**
localPort: 5360
pid: 7480
2016-04-08 14:36:10 -06:00
tunnel established from localhost:5360 to xyz.xy.xyz.yz:5432 as root
2016-04-08 14:28:58 -06:00
**connected**
localPort: 40321
pid: 7481
2016-04-08 14:36:10 -06:00
tunnel established from localhost:40321 to xyz.xy.xyz.yz:5432 as root
2016-04-08 14:28:58 -06:00
*/