Skip to content

Instantly share code, notes, and snippets.

@nax3t
Created May 10, 2019 18:34
Show Gist options
  • Save nax3t/1bcd39627a2cd4c2ef70a439baea9423 to your computer and use it in GitHub Desktop.
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
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