wireguard-tools.js v1.8.1
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);
3 months ago
3 months ago
4 months ago
4 months ago
5 months ago
9 months ago
9 months ago
7 months ago
9 months ago
9 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago