Created
March 28, 2017 03:43
-
-
Save zhoukekestar/090d93e0afde6a38603bb019b77cee12 to your computer and use it in GitHub Desktop.
Fastest IP for you!
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
const exec = require('child_process').exec; | |
const ping = (ip) => { | |
return new Promise((resolve, reject) => { | |
exec(`ping ${ip}`, (err, stdout, stderr) => { | |
if (err) { | |
reject(err); | |
return; | |
} | |
resolve({ip, stdout}); | |
}); | |
}); | |
} | |
var ips = ` | |
8.7.198.45 | |
203.98.7.65 | |
54.192.72.90 | |
46.82.174.68 | |
59.24.3.173 | |
54.192.72.87`.split(/\s{1,}/g).filter((ip) => ip.length > 0); | |
Promise.race(ips.map((ip) => ping(ip))).then(({ip, stdout}) => { | |
console.log(`${ip} is best`); | |
console.log(stdout) | |
}).catch((e) => { | |
console.log(e); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment