如何在Ubuntu中使用Node.js连接VPN

Pro*_*fer 8 javascript vpn node.js ubuntu-16.04 privoxy

我的nodejs文件中有代码,可以提供以下信息

host:"147.0.40.145"
method:"aes-256-cfb"
password:"9c359ad1ebeec200"
port:38473
Run Code Online (Sandbox Code Playgroud)

我需要使用以上信息,并希望通过它连接VPN。我使用下面的代码来提取上述信息。

const connectServer = (serverId) => {
  const token = store('access_token')
  httpOptions.Authorization = token.token_type+' '+token.access_token
  return new Promise((resolve, reject) => {  
   const response = await axios.post(`${baseUrl}/servers/${serverId}/connect`, {'serverId':serverId},{headers: httpOptions})     
   console.log(response.data)
    resolve(response.data)
  })
}
Run Code Online (Sandbox Code Playgroud)

所以,我需要知道是否有可能使用nodejs到连接或创建 VPN?

先感谢您!!!

Sac*_*hah 7

安装这个 npm

npm i node-openvpn --save

const openvpnmanager = require('node-openvpn');

const opts = {
  host: '147.0.40.145',
  port: 38473,
  timeout: 1500, //timeout for connection - optional, will default to 1500ms if undefined
  logpath: 'log.txt' //optional write openvpn console output to file, can be relative path or absolute
};
const auth = {
  user: '{{add user name}}',
  pass: '9c359ad1ebeec200',
};
const openvpn = openvpnmanager.connect(opts)


 openvpn.on('connected', () => {
   console.log("Connected to VPN successfully...");
 });
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息,请阅读此链接

另一种选择 链接