why can not find the port that is listening
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.8k
- Forks
- 734
- PR merge metrics
- No merged PRs in 30d
Description
I want to fill a function like a ssh command
"ssh -N -o "ServerAliveInterval=15" -o "ServerAliveCountMax=1" -R $port:localhost:22 user@host"
map the ssh port of localhost to remote
So I use the code generate by AI:
function createReverseTunnel(sshPort, remoteHost, remotePort) {
const conn = new Client();
conn.on('ready', () => {
console.log('SSH connection established');
conn.forwardOut(
'0.0.0.0',
sshPort,
remoteHost,
remotePort,
(err, stream) => {
if (err) {
console.error('Forwarding failed:', err);
return;
}
console.log(`Reverse tunnel established: ${remoteHost}:${remotePort} -> localhost:${sshPort}`);
stream.on('close', () => {
console.log('TCP :: CLOSED');
}).on('error', (err)=>{
console.log('TCP :: ERROR', err);
}).on('data', (data) => {
console.log('TCP :: DATA: ' + data);
})
stream.write('GET / HTTP/1.1\r\n' +
'Host: aliyun.com\r\n' +
'Connection: close\r\n' +
'\r\n');
} );
}).on('error', (err) => {
console.error('SSH connection error:', err);
}).on('end', () => {
console.log('SSH connection ended');
}).on('close', (had_error) => {
console.log(SSH connection closed${had_error ? ' due to error' : ''});
});
conn.connect({
host: remoteHost,
port: 22,
username: 'root',
password: 'password',
keepaliveInterval: 15000,
keepaliveCountMax: 1,
});
}
createReverseTunnel( 22222, 'aliyun', 80 );
Program run ok,got the response from aliyun:80
But I want to get the same function like "ssh -N -o "ServerAliveInterval=15" -o "ServerAliveCountMax=1" -R $port:localhost:22 user@host", I can not find which port is listening both local and remote.
Who can help me to fullfil the function, thanks
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the requested ssh -R behavior with the shown createReverseTunnel function and its conn.forwardOut call. Determine which ssh2 forwarding API or entry point supports listening on the remote host; done means the example creates the requested remote listener and documents how its local and remote ports are identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100