feat: add ping function
This commit is contained in:
9
wol.js
9
wol.js
@@ -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(/[:-]/);
|
||||||
@@ -39,3 +40,11 @@ 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user