From 163d995008d2969c4883bd2a4cae780a29d5e41b Mon Sep 17 00:00:00 2001 From: rosa Date: Tue, 3 Feb 2026 00:15:32 +0100 Subject: [PATCH] feat: add ping function --- wol.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wol.js b/wol.js index b1a4cd9..478eaa2 100644 --- a/wol.js +++ b/wol.js @@ -1,4 +1,5 @@ import dgram from "node:dgram" +import { exec } from "node:child_process"; export function createWolPacket(mac) { 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); + }); + }); } \ No newline at end of file