JS前端获取客户端IP的方法基本都是通过三方接口:

常用的方法1:

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
document.write(returnCitySN["cip"]+','+returnCitySN["cname"])
</script>

常用的方法2:

var first = document.body.firstChild;
var oScript = document.createElement("script");
oScript.src =
"http://pv.sohu.com/cityjson?ie=utf-8&callback=returnCitySN&t=" + new Date().getTime();
document.body.insertBefore(oScript, first);
document.onclick = () => console.log(returnCitySN)

看输出就是IP地址了

相关文章:

  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2021-09-04
  • 2021-10-02
相关资源
相似解决方案