请问有没有办法用js直接获取手机的ip地址呢
1赞
这个搜狐接口我知道,但是我要怎么样可以调用他里面的内容呢
这个搜狐接口我知道,但是我要怎么样可以调用他里面的内容呢~~
这个咋获取中间的ip字段啊????
var data = (new Function(response + ‘return returnCitySN;’))();
这么干怎么样?
responseText.match(/(?<=“cip”: ")[0-9.]+/)[0]
有一个有趣的网站 https://ifconfig.co/
通xhr来获取ip的json数据
var url = “https://ifconfig.co/json”;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
var response = xhr.responseText;
console.log(response);
}
};
xhr.open(“GET”, url, true);
xhr.send();
但这里有跨域的问题
解决跨域 参考http://forum.cocos.com/t/url/42848/4
服务器都有了,自己随便搞个接口就能获取到IP了,还用得着别人提供的接口
1赞
你说的有道理, 赞
能不能获取内网的ip(192.168这种的)