【问题标题】:Sending ip and receiving location using ajax使用ajax发送ip和接收位置
【发布时间】:2019-10-05 14:56:16
【问题描述】:

我想知道任何网站网页,我可以在其中发送用户 IP 地址并以纯文本/文本形式接收他们的国家/地区。

作为参考,我已经在下面的代码sn-p中演示了。

我尝试执行以下代码来恢复用户 IP。

<script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>

...

<script type="text/javascript">
  document.write("Your IP is :", userip);
</script>

$.post("domain.sdm/page", {
    "ip": "123.234.345"
}, function(dat,suc) {
    alert("Your country is: "+ dat);
});

【问题讨论】:

    标签: javascript ajax location ip


    【解决方案1】:

    一个很好的网站是https://iplocation.com/

    如果您在 POST 请求中发送 IP 地址,您将收到包含大量有关 IP 地址的信息的捆绑包,包括城市和国家/地区。

    IP 地址也由 4 个字节组成,这意味着 4 个数字上升到 2^8,而不是 3。

    !免责声明!由于 CORS 政策,您必须通过 https://cors-anywhere.herokuapp.com 传递 URL,否则您的请求将被阻止,因为您将执行来自另一个域的请求。

    $.post("https://cors-anywhere.herokuapp.com/https://iplocation.com", {
        "ip": "124.84.42.76" //for example but watch out some ip addresses might not exist
    }, function(dat,suc) {
        alert("Your country is: "+ dat.country_name);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-10
      • 1970-01-01
      • 2017-10-24
      • 2011-09-13
      • 1970-01-01
      相关资源
      最近更新 更多