Q:

let javascript deside wether to link to internal or external webadress

For my new website I'm trying to setup a html with a little javascript which decides whether to link to the external or internal ip. 
I looked up some javascript to request the ip, which I found.
$.getJSON('//api.ipify.org?format=jsonp&callback=?', function(data) {

console.log(JSON.stringify(data, null, 2));
});
which should return this:
{
  "ip": "116.12.250.1"
}

the point here is that I do not understand how to use this output. 
The first thing I thought of was to write a little javascript using conditions (https://www.w3schools.com/js/js_if_else.asp) But I just don't understand how to use this output in this way.
The essential idea of my plan is for the website to find out whether the client is on the wan or lan network, using this request. And then decide whether to link the href to an external ip; (wan.wan.wan.wan) or internal ip; (lan.lan.lan.lan)
so this is what I came up with
    if ("wan.wan.wan.wan" == "[the ip the website is hosted on]")
{ "[href variable]" = "lan.lan.lan.lan }

else if ("wan.wan.wan.wan" != "[the ip the website is hosted on]")
{ "[href variable]" = "wan.wan.wan.wan"}

I had a bit of a hard time explaining it, sorry for that. I'm originally dutch so, forgive me.
Please ask if my question is unclear in any way!!!
thanks in advance!

A:

You can use the request to get the IP address, then save it:
$.getJSON('//api.ipify.org?format=jsonp&callback=?', function(data) {
    var ip = (JSON.stringify(data, null, 2)); })['ip'];
}

Now that you have the IP address, you can determine if they're on the same network as the server by looking at the IP address, but you can omit the digits following the final .
Because if you connect two computers to the same network, one might have the address 10.10.10.10, and the other 10.10.10.11, etc.
So you check if the first 3 chunks of the visitor's IP matches the IP of your server, which is known:
$.getJSON('//api.ipify.org?format=jsonp&callback=?', function(data) {
            var ip = (JSON.stringify(data, null, 2))['ip'];

            if (ip.match(/100.100.100.d{0,3}/)) { //REPLACE 100.100.100 WITH YOUR SERVER'S IP
                //user is on the same network
            } else {
                //user is not on the same network
            }
        }

