feat: add ping function

This commit is contained in:
2026-02-03 00:15:32 +01:00
parent e01c267e30
commit 163d995008

9
wol.js
View File

@@ -1,4 +1,5 @@
import dgram from "node:dgram" import dgram from "node:dgram"
import { exec } from "node:child_process";
export function createWolPacket(mac) { export function createWolPacket(mac) {
const parts = mac.split(/[:-]/); const parts = mac.split(/[:-]/);
@@ -38,4 +39,12 @@ export async function sendWolPacket(mac, broadcast = "255.255.255.255", port = 9
}); });
}); });
}); });
}
export function ping(ip) {
return new Promise(resolve => {
exec(`ping -c 1 -W 1 ${ip}`, err => {
resolve(!err);
});
});
} }