S
S
sasha-ld2021-08-17 17:23:53
openvpn
sasha-ld, 2021-08-17 17:23:53

Nodejs how to connect to Openvpn via telnet?

There is a server with Openvpn, if I want to connect telnet localhost 7505 in the console, then everything is fine, but when in nodejs, then an error

const net = require('net');
const client = net.createConnection({
    host: '127.0.0.1',
    port: 7505
}, () => {
  //'connect' listener
  console.log('connected to server!');
  client.write('status');
});
client.on('data', (data) => {
  console.log(data.toString());
  client.end();
});
client.on('end', () => {
  console.log('disconnected from server');
});

I get this in response
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:7505
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
Emitted 'error' event at:
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

What's the matter, who knows?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Babichev, 2021-08-17
@sasha-ld

Do you want to connect to your application via OpenVPN? The application fumbles the port only locally, but it needs to be on the IP that looks on the Internet. If you replace 127.0.0.1 with 0.0.0.0, then you will rummage around the application everywhere. In theory, this is what you need
Replace with PS, it 's better to replace 0.0.0.0 with IP inside the VPN network, it's safer. For example, 10.10.10.1.
host: '127.0.0.1',
host: '0.0.0.0',

S
sasha-ld, 2021-08-17
@sasha-ld

No, I want to make a simple web interface for myself to manage clients connected to my server. Openvpn server is installed on the server and teamspeak3 server is also installed.
To manage teamspeak3 server there is a management interface via telnet
When connecting to teamspeak

const net = require('net');
const client = net.createConnection({
    host: '127.0.0.1',
    port: 10011
}, () => {
  //'connect' listener
  console.log('connected to server!');
  client.write('status');
});
client.on('data', (data) => {
  console.log(data.toString());
  client.end();
});
client.on('end', () => {
  console.log('disconnected from server');
});

everything is fine, I get the answer
connected to server!
TS3
Welcome to the TeamSpeak 3 ServerQuery interface, type "help" for a list of commands and "help <command>" for information on a specific command.

disconnected from server

when connecting to openvpn management interface
const net = require('net');
const client = net.createConnection({
    host: '127.0.0.1',
    port: 7505
}, () => {
  //'connect' listener
  console.log('connected to server!');
  client.write('status');
});
client.on('data', (data) => {
  console.log(data.toString());
  client.end();
});
client.on('end', () => {
  console.log('disconnected from server');
});

I get an error
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:7505
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
Emitted 'error' event at:
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question