1.8.1 • Published 3 months ago

wireguard-tools.js v1.8.1

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
3 months ago

Wireguard-tools.js

A quick way to use Wireguard with Node.js without having to run the Wireguard tools. We've included some wg command patterns to avoid confusion and to maintain a base between the tools.

In addition to having some basic utilities already integrated:

  • Keygen: Generate private and public keys and also a pre-shared key.
  • Config file: You can generate files for Wireguard directly from here and you can transform a configuration file into a JSON.

To manage Wireguard interfaces:

  • Create a new Wireguard network interface and configure it with the provided information.
  • Delete Interface.
  • Get the peers along with the interface and peer information.

Example

Parse wireguard configuration file:

import { readFileSync } from "node:fs";
import { utils } from "wireguard-tools.js";
const configFile = readFileSync("/etc/wireguard/wg0.conf", "utf8");
const configJson = utils.config.parseConfig(configFile);
console.log("Config file JSON:\n%o", configJson.data);

Create Config:

import { utils } from "wireguard-tools.js";
const wireguardConfig = utils.config.writeConfig({
  interface: {
    private: "CEOntDE9saQaHLhD/WzZuYky3+elOfnBUCXoSveD3kc=",
    public: "xaZtpi3VCkBMhSTKM6jl/YjPJ370iYpBlLYwSyZ3W08=",
    address: [
      {
        ip: "10.0.0.1",
        subnet: 24
      }
    ]
  },
  peer: {
    "tF4YxTqLIJdNQcqvz1jtIF993zSk79hP+zdBxQlaowA=": {
      Keepalive: 25,
      Endpoint: {
        host: "wireguard.example.com",
        port: 51820
      },
    }
  }
});
console.log("Config file:\n%s", wireguardConfig);

or

Note

To save to wireguard's default directory (/etc/wireguard), it is necessary to have root access or a user with write permissions on the directory.

import { utils } from "wireguard-tools.js";
utils.config.writeConfig({
  interface: {
    private: "CEOntDE9saQaHLhD/WzZuYky3+elOfnBUCXoSveD3kc=",
    public: "xaZtpi3VCkBMhSTKM6jl/YjPJ370iYpBlLYwSyZ3W08=",
    address: [
      {
        ip: "10.0.0.5",
        subnet: 24
      }
    ]
  },
  peer: {
    "tF4YxTqLIJdNQcqvz1jtIF993zSk79hP+zdBxQlaowA=": {
      Keepalive: 25,
      Endpoint: {
        host: "wireguard.example.com",
        port: 51820
      },
    }
  }
}, "wg0");

Get Current peers and Statistics:

import { show } from "wireguard-tools.js";
const wireguardInterfaces = show("wg0");
// Wg0 is the interface name.
console.log("Wg0:\n%o", wireguardInterfaces);
2.0.1

3 months ago

2.0.0

3 months ago

1.8.3

4 months ago

1.8.2

4 months ago

1.8.1

5 months ago

1.7.3

9 months ago

1.7.2

9 months ago

1.8.0

7 months ago

1.7.1

9 months ago

1.7.0

9 months ago

1.7.8

8 months ago

1.7.7

8 months ago

1.7.6

8 months ago

1.7.5

9 months ago

1.7.4

9 months ago

1.5.3

1 year ago

1.6.0

1 year ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.3

2 years ago