Created
May 10, 2019 18:34
-
-
Save nax3t/1bcd39627a2cd4c2ef70a439baea9423 to your computer and use it in GitHub Desktop.
node script to ping wifi every 10 minutes and restart it if it's down
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 shell = require('shelljs'); | |
const rp = require('request-promise'); | |
async function testWifi() { | |
let count = 0; | |
try { | |
const result = await rp('http://www.google.com'); | |
if (result) { | |
console.log('wifi working'); | |
} | |
} catch(err) { | |
count++; | |
console.log(err.message, `fail # ${count}`); | |
shell.exec('networksetup -setairportpower en0 off'); | |
shell.exec('networksetup -setairportpower en0 on'); | |
} | |
} | |
setInterval(testWifi, 600000); // 10 minutes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment