Skip to content

Instantly share code, notes, and snippets.

@DaveyJake
Last active May 21, 2020 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveyJake/93b898e1a52a8a95e903e87e6ae1a3d2 to your computer and use it in GitHub Desktop.
Save DaveyJake/93b898e1a52a8a95e903e87e6ae1a3d2 to your computer and use it in GitHub Desktop.
iStat Pro Widget 4.9.2: Restore External IP Support
/**
* Get your current external IP address for the iStat Pro dashboard widget.
*
* For those of us who refuse to let go of the iStat Pro dashboard widget (version 4.9.2),
* this function is located inside of `~/Library/Widgets/iStat\ Pro.wdgt/scripts/core.js`
* beginning at line 243. As of when this Gist was published, Bjango killed the endpoint
* that powered their external IP address service. Thankfully, there's
* {@link https://www.ipify.org}, a free public IP API endpoint. Simply copy and paste the
* function below over the predecessor inside the core.js file and the IP service is
* restored (once again).
*
* @link https://mac.softpedia.com/get/Dashboard-Widgets/Status-Info/iStat-pro.shtml
*
* @author Bjango
* @link https://bjango.com
* @version 4.9.2
*/
function getExtIP(){
ipURL = 'https://api.ipify.org?format=json';
ipConnection = new XMLHttpRequest();
ipConnection.open("GET", ipURL, true);
ipConnection.onreadystatechange = function() {
if(ipConnection.readyState == 4 && ipConnection.responseText != null && ipConnection.responseText.length > 0) {
extIP = JSON.parse(ipConnection.responseText);
extIP = extIP.ip;
if(extIP.length < 20 && ipConnection.status == 200 && extIP.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)){
e("wide_extip").innerHTML = extIP;
e("tall_extip").innerHTML = extIP;
valid_ip = true;
} else {
valid_ip = false;
e("wide_extip").innerHTML = "Unknown";
e("tall_extip").innerHTML = "Unknown";
}
}
}
ipConnection.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment