简体   繁体   English

JavaScript 获取客户端 IP 地址绕过浏览器扩展

[英]JavaScript to get Client IP Address bypassing Browser Extensions

I am using an external API and part of the parameter of the API is an IP address.我正在使用外部 API 和 API 的部分参数是 IP 地址。 I looked up how to do it and I used the ipify version in this answer because it has no limitations.我查了怎么做,我在这个答案中使用了ipify版本,因为它没有限制。 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.它运行良好,直到一些客户端被显示错误,根据日志,这是因为他们的 IP 地址丢失。 I narrowed it down to their browser extension, uBlock Origin , which was preventing the script from running.我将其范围缩小到他们的浏览器扩展程序uBlock Origin ,它阻止了脚本运行。

Is there a more reliable way to do this without having to do any upgrade to paid tiers?有没有更可靠的方法可以做到这一点而无需升级到付费层?

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.您可以使用未被广告拦截器列入黑名单的公共服务,例如https://www.myexternalip.com/json但最终它也可以被列入黑名单,它不受您的控制。

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.可能你不花一些钱就不会摆脱你的“问题”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM