1

I am using an external API and part of the parameter of the API is an IP address. I looked up how to do it and I used the ipify version in this answer because it has no limitations. Here is the script:

$.getJSON('https://api.ipify.org?format=jsonp&callback=?', function(data) {
  console.log(data); 
  console.log(data.ip.toString()); 

  retrieved_entity_ip = data.ip.toString();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

It's working so well until some clients were being shown errors and according to the logs it was because their IP address was missing. I narrowed it down to their browser extension, uBlock Origin, which was preventing the script from running.

Is there a more reliable way to do this without having to do any upgrade to paid tiers?

Prosy Arceno
  • 2,616
  • 1
  • 8
  • 32
  • 2
    Your API treats IPs as credentials? – Guerric P May 05 '21 at 18:06
  • 1
    @GuerricP. yes. its in their [documentation](https://docs.fundamerica.com/#15c00406-a1f3-4a9b-a0d2-eaa648b8e6a4) so I believe I can share it as well. – Prosy Arceno May 05 '21 at 18:14
  • 2
    Interesting. I don't get what's the purpose, and how they validate this address. – Guerric P May 05 '21 at 18:21
  • Does this answer your question? https://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript – esqew May 09 '21 at 00:45
  • No. That's where I got my current answer as posted in my question – Prosy Arceno May 09 '21 at 00:46
  • 2
    In that event, I would encourage you to throw an error if the client can’t connect to your external service, with a message telling them to disable their network-blocking extensions. – esqew May 09 '21 at 00:46
  • If it were up to me, I'd do just that. I would even send a local IP just to get this working. But it needs a legit IP retrieved in a background process. – Prosy Arceno May 09 '21 at 00:51
  • 1
    You could host your own ipify server. ipify is blacklisted https://github.com/rdegges/ipify-api/issues/18. you'd probably fly under the radar – Millie Smith May 09 '21 at 00:55
  • Where do you see anything about an IP address in that API documentation? I don't see it at your link. – Brad May 09 '21 at 01:04
  • 1
    @Brad Click view more on the "example request" on the right. The field name is "ip_address" – Millie Smith May 09 '21 at 01:14

1 Answers1

4

You can use public services which are not blacklisted by ad blockers, like https://www.myexternalip.com/json but eventually it can also be blacklisted, it's not under your control.

The most reliable way to reduce the risk of using a service that can be blacklisted would be building your own server as suggested in descriptions or keeping an updated list of alternative services in case of failed requests. Probably you won't get rid of your "problem" without spending some money.

natenho
  • 5,231
  • 4
  • 27
  • 52
  • Does this have any limitations? Something like 400 requests a day? – Prosy Arceno May 10 '21 at 00:35
  • @ProsyArceno according to the service, "if you exceed the rate limit of 30 requests/minute, you will receive status code 429". This is per IP, so since your script is on the client side, I wouldn't worry about that, unless you have many users behind an internet gateway. – natenho May 10 '21 at 01:01
  • That's fine. I'll use this for now thanks – Prosy Arceno May 10 '21 at 01:03