JS浏览器获取本地IP的方法

转载来自:https://blog.csdn.net/qq_35855343/article/details/108706136

现在用的比较多的第三方免费开放接口一般是搜狐提供的接口:http://pv.sohu.com/cityjson?ie=utf-8。

所以通过script标签引入这个接口就可以了,这样还可以避免跨域的问题。
话不多说,上代码(亲测有效):

<!DOCTYPE html>
<html>
<head>
<title>get Ip and MAC!</title>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
</head>
<body>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
document.write(returnCitySN["cip"]+','+returnCitySN["cname"])
</script>
</body>
</html>
posted @ 2021-06-10 11:32  冰糖葫芦很乖  阅读(1284)  评论(0编辑  收藏  举报