网站开发分前台后台,网站建设建构,一个备案可以做几个网站,wordpress分类目录表检测前端是否可以ping通后端返回的ip地址 前端检测是否可ping通ip地址#xff08;PC端#xff09;前端检测是否可ping通ip地址#xff08;uniapp小程序端#xff09; 前端检测是否可ping通ip地址#xff08;PC端#xff09;
// 前端检测是否可ping通ip地址
ping… 检测前端是否可以ping通后端返回的ip地址 前端检测是否可ping通ip地址PC端前端检测是否可ping通ip地址uniapp小程序端 前端检测是否可ping通ip地址PC端
// 前端检测是否可ping通ip地址
pingFn(ips) {let promiseArr [];ips.forEach(ip{// debuggerlet pro new Promise((res, rej){let img new Image();let start new Date().getTime();img.src https:// ip ?t start;img.onload function() {res({code:200,status: true,ip});};img.onerror function() {res({code:200,status: true,ip});};let timer setTimeout((){clearTimeout(timer);rej();}, 1500);}).catch((e) {});promiseArr.push(pro);});return Promise.any(promiseArr);
},前端检测是否可ping通ip地址uniapp小程序端
// 前端检测是否可ping通ip地址
pingFn(ips) {let promiseArr [];ips.forEach(ip{let pro new Promise((res, rej){let start new Date().getTime();let url https:// ip ?t start;uni.getImageInfo({ src: url, success: function (image) { res({code:200,status: true,ip});}, fail:function(err){ res({code:200,status: true,ip});} }); let timer setTimeout((){clearTimeout(timer);rej();}, 1500);}).catch((e) {});promiseArr.push(pro);});return Promise.any(promiseArr);
},async getData() {let a await this.pingFn([192.168.0.12,192.168.0.13]);// console.log(检测是否能ping通内网地址,a)if(a){// 如果有返回值则可以ping通}else{// 无返回值会返回undefined}// 根据返回值执行自己的后续操作
}首先实现的是PC端功能后粘贴到小程序里发现实现不了代码一行行定位后发现在new Image()那一步就已经走不下去了后百度发现脚本不支持Image对象将写法改一下即可。 参考文档 1、vue2实现前端ping 后端给的ip地址是否可以ping通【https://blog.csdn.net/weixin_43845137/article/details/130371232】 2、uni-app在脚本中不支持Image对象【https://ask.dcloud.net.cn/question/76390】