I need your help about how return the response to execute cmd on telnet-client, in this momment just have te response in the event 'ready' but don´t have return to principal funcion.
this is my code
const testTelnet = async (host, dns) => {
process.on('unhandledRejection', error => {
console.log("**TELNET CONNECTION ERROR ***", error);
});
const params = {
host: host,
port: 23,
shellPrompt: '#',
negotiationMandatory: false,
loginPrompt: dns + ' login:',
username: user,
password: password,
failedLoginMatch: '/error en autenticacion/',
timeout: 5000,
}
const res = connection.on('ready', prompt => {
connection.exec(cmd, (err, response) => {
console.log("pront", prompt);
console.log(response)
return response; // **** NEED RETURN THIS RESPONSE
})
})
console.log("resultado: ", res)
connection.on('timeout', () => {
console.log('socket timeout!')
connection.end()
})
connection.on('close', () => {
console.log('connection closed')
})
connection.connect(params)
return response;
}