iStat Pro Widget External IP Fix

Open the $HOME/Library/Widgets/iStat Pro.wdgt/scripts/core.js script in a text editor, find the getExtIP() function and replace the following line:
ipURL = 'http://whatsmyip.islayer.com/?random='+new Date().getTime();

with this (or a similiar "what's my ip" service URL):
ipURL = 'http://www.whatsmyip.us/showipsimple.php?random='+new Date().getTime();

And the following:
if(extIP.length < 20 && ipConnection.status == 200 && extIP.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)){

With these:
ip_regex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}";
if(extIP.length < 100000 && ipConnection.status == 200 && extIP.match(new RegExp(ip_regex))){
    extIP = extIP.replace(new RegExp("^(.*[^\\d])?(" + ip_regex + ")([^\\d].*)?$"), "$2");

This patch lets you use quite many "what's my IP" services since the the script will take the first IP looking string from the result of the HTTP request.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

ipslayer.com and whatsmyip.us replacement

ipslayer.com and whatsmyip.us and are no longer in service.
ipify.org is a drop-in replacement for the original code:
        ipURL = 'http://api.ipify.org/?format=xml';
        ipConnection = new XMLHttpRequest();
        ipConnection.open("GET",ipURL,true);
        ipConnection.onreadystatechange = function() {
                if(ipConnection.readyState == 4 && ipConnection.responseText != null && ipConnection.responseText.length > 0) {
                        extIP = ipConnection.responseText;
                        if(ipConnection.status == 200)

Re: ipslayer.com and whatsmyip.us replacement

Thanks for the feedback!

does not work

your code does not work for me. iStat not able to start with this code.

Re: does not work

It's because my post is more than a year old and the IP checking service (www.whatsmyip.us) is no more. This was already mentioned by somebody in an anonymous comment. You should find another IP checking service. Eg. ipify.org is a drop-in replacement (as mentioned by the same comment).

missing close quote in first line

Should be:

ipURL = 'http://api.ipify.org/?format=xml';

Re: missing close quote in first line

Thanks! I've corrected this in the anonymous comment so others don't get stuck while copy&pasting it.

Don't forget to killall Dock

Thanks for fixing my typo.
If you have just made this fix:
sudo killall Dock
to force the existing iStat to load the new code

New Fix

To maque it work now (11 December 2016)


function getExtIP(){
ipURL = 'http://api.ipify.org/?format=xml';
ipConnection = new XMLHttpRequest();
ipConnection.open("GET",ipURL,true);
ipConnection.onreadystatechange = function() {
if(ipConnection.readyState == 4 && ipConnection.responseText != null && ipConnection.responseText.length > 0) {
extIP = ipConnection.responseText;
extIP_len = extIP.length;
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);
}

Syndicate content