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地址了