How to connect VPN using nodejs in ubuntu

社会主义新天地 提交于 2020-06-13 19:24:05

问题


I have the code in my nodejs file which gives me the following information

host:"147.0.40.145"
method:"aes-256-cfb"
password:"9c359ad1ebeec200"
port:38473

I need to use above information and want to connect VPN through it. I have used below code to extract the above information.

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)
  })
}

So I need to know whether it is possible using nodejs to connect or create VPN?

Thank you in advance!!!


回答1:


Install this 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...");
 });

For more info , please read this link

Another option Link



来源:https://stackoverflow.com/questions/55449569/how-to-connect-vpn-using-nodejs-in-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!