This repository has been archived by the owner on May 22, 2021. It is now read-only.
forked from rhpijnacker/rehearse20
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7881a6c
commit f9f52d4
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import child_process from 'child_process'; | ||
|
||
export default function ping(target) { | ||
return new Promise((resolve) => { | ||
let min, avg, max; | ||
const child = child_process.spawn('ping', [target, '-c', '10', '-A']); | ||
child.stdout.on('data', function (msg) { | ||
msg = msg.toString(); | ||
console.log(`"${msg}"`); | ||
const match = msg.match( | ||
/rtt min\/avg\/max\/mdev = ([\d.]+)\/([\d.]+)\/([\d.]+)\/([\d.]+) ms/ | ||
); | ||
if (match) { | ||
console.log('match', match) | ||
min = parseFloat(match[1]); | ||
avg = parseFloat(match[2]); | ||
max = parseFloat(match[3]); | ||
} | ||
}); | ||
child.on('close', () => resolve({ min, avg, max })); | ||
}); | ||
} |