代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="favicon.png">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" />
<!--<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">-->
<meta charset="UTF-8" />
<script type="text/javascript" src="speedtest.js"></script>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function I(i){return document.getElementById(i);}
//LIST OF TEST SERVERS. See documentation for details if needed
var SPEEDTEST_SERVERS=[
{ //this is my demo server, remove it
name:"VPN",
server:"//nettest.vipkid.com.cn/",
// server:"http://172.20.251.18:88/",
// server:"http://114.113.81.13/",
dlURL:"garbage.php",
ulURL:"empty.php",
pingURL:"empty.php",
getIpURL:"getIP.php"
},
// { //this is my demo server, remove it
// name:"邮箱", //user friendly name for the server
// server:"//nettest.vipkid.com.cn/", //URL to the server. // at the beginning will be replaced with http:// or https:// automatically
// dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
// ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
// pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
// getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
// },
//add other servers here, comma separated
];
//INITIALIZE SPEEDTEST
var s=new Speedtest(); //create speedtest object
s.setParameter("telemetry_level","basic"); //enable telemetry
s.addTestPoints(SPEEDTEST_SERVERS); //add list of servers
//SERVER AUTO SELECTION
function initServers(){
s.selectServer(function(server){
if(server!=null){ //at least 1 server is available
I("loading").className="hidden"; //hide loading message
//populate server list for manual selection
for(var i=0;i<SPEEDTEST_SERVERS.length;i++){
if(SPEEDTEST_SERVERS[i].pingT==-1) continue;
var option=document.createElement("option");
option.value=i;
option.textContent=SPEEDTEST_SERVERS[i].name;
if(SPEEDTEST_SERVERS[i]===server) option.selected=true;
I("server").appendChild(option);
}
//show test UI
I("testWrapper").className="visible";
initUI();
}else{ //no servers are available, the test cannot proceed
I("message").innerHTML="服务器节点不可达,建议重新登录VPN或咨询IT支持!";
}
});
}
var meterBk=/Trident.*rv:(\d+\.\d+)/i.test(navigator.userAgent)?"#EAEAEA":"#80808040";
var dlColor="#f85415",
ulColor="#f85415";
pingColor="#f85415",
jitColor="#f85415";
var progColor=meterBk;
//CODE FOR GAUGES
function drawMeter(c,amount,bk,fg,progress,prog){
var ctx=c.getContext("2d");
var dp=window.devicePixelRatio||1;
var cw=c.clientWidth*dp, ch=c.clientHeight*dp;
var sizScale=ch*0.0055;
if(c.width==cw&&c.height==ch){
ctx.clearRect(0,0,cw,ch);
}else{
c.width=cw;
c.height=ch;
}
ctx.beginPath();
ctx.strokeStyle=bk;
ctx.lineWidth=12*sizScale;
ctx.arc(c.width/2,c.height-58*sizScale,c.height/1.8-ctx.lineWidth,-Math.PI*1.1,Math.PI*0.1);
ctx.stroke();
ctx.beginPath();
ctx.strokeStyle=fg;
ctx.lineWidth=12*sizScale;
ctx.arc(c.width/2,c.height-58*sizScale,c.height/1.8-ctx.lineWidth,-Math.PI*1.1,amount*Math.PI*1.2-Math.PI*1.1);
ctx.stroke();
if(typeof progress !== "undefined"){
ctx.fillStyle=prog;
ctx.fillRect(c.width*0.3,c.height-16*sizScale,c.width*0.4*progress,4*sizScale);
}
}
function mbpsToAmount(s){
return 1-(1/(Math.pow(1.3,Math.sqrt(s))));
}
var w=null; //speedtest worker
var data=null; //data from worker
function msToAmount(s){
return 1-(1/(Math.pow(1.08,Math.sqrt(s))));
}
function format(d){
d=Number(d);
if(d<10) return d.toFixed(2);
if(d<100) return d.toFixed(1);
return d.toFixed(0);
}
//UI CODE
var uiData=null;
var stop_flag = "";
function startStop(){
if(s.getState()==3){
//speedtest is running, abort
s.abort();
data=null;
I("startStopBtn").className="";
I("server").disabled=false;
initUI();
stop_flag = "yes"
uiData = "";
}else{
//test is not running, begin
I("startStopBtn").className="running";
I("shareArea").style.display="none";
I("server").disabled=true;
s.onupdate=function(data){
uiData=data;
};
s.onend=function(aborted){
I("startStopBtn").className="";
I("server").disabled=false;
updateUI(true);
console.log("返回结果 --->", JSON.stringify(uiData));
// I("resultsURL").value=JSON.stringify(uiData);
// "pingStatus":"21.55" , "dlStatus":"7.75",
// str_uiData = JSON.stringify(uiData)
pingStatus = uiData.pingStatus;
dlStatus = uiData.dlStatus;
var result_1_1 = ""
var result_1_2 = ""
var result_2_1 = ""
var result_2_2 = ""
if( !aborted && uiData ) {
I("shareArea").style.display="";
if (pingStatus > 0 && pingStatus <= 150) {
result_1_1 = "网络连通性:";
result_1_2 = "优良<br>";
result_2_1 = "端口检测:";
result_2_2 = "正常<br>";
I("testId_1.2").style.color = "#4FAC5B";
I("testId_2.2").style.color = "#4FAC5B";
pingColor = "#4FAC5B",
jitColor = "#4FAC5B";
} else if (pingStatus > 150 && pingStatus <= 350) {
result_1_1 = "网络连通性:";
result_1_2 = "正常<br>";
result_2_1 = "端口检测:";
result_2_2 = "正常<br>";
I("testId_1.2").style.color = "#2971BB";
I("testId_2.2").style.color = "#4FAC5B";
pingColor = "#2971BB";
jitColor = "#2971BB";
} else if (pingStatus > 350 && pingStatus <= 500) {
result_1_1 = "网络连通性:";
result_1_2 = "一般<br>";
result_2_1 = "端口检测:";
result_2_2 = "正常<br>";
I("testId_1.2").style.color = "#E08043";
I("testId_2.2").style.color = "#4FAC5B";
pingColor = "#E08043";
jitColor = "#E08043";
} else if (pingStatus > 500 && pingStatus <= 1000) {
result_1_1 = "网络连通性:";
result_1_2 = "很差,建议检查本地网络环境!<br>";
result_2_1 = "端口检测:";
result_2_2 = "正常<br>";
I("testId_1.2").style.color = "#B22218";
I("testId_2.2").style.color = "#4FAC5B";
pingColor = "#B22218";
jitColor = "#B22218";
} else {
result_1_1 = "网络连通性:";
result_1_2 = "检测失败,建议重启VPN或咨询IT支持!<br>";
result_2_1 = "端口检测:";
result_2_2 = "失败<br>";
I("testId_1.2").style.color = "red";
I("testId_2.2").style.color = "red";
pingColor = "red";
jitColor = "red";
}
// 当前网速相当于20M~50M宽带,已超越全国52%的网络用户
if (dlStatus > 0 && dlStatus < 5) {
result_3_1 = "网络速度:";
result_3_2 = "很差<br>";
I("testId_3.2").style.color = "#B22218";
dlColor = "#B22218"
ulColor = "#B22218";
} else if (dlStatus >= 5 && dlStatus < 10) {
result_3_1 = "网络速度:";
result_3_2 = "一般 <br>";
I("testId_3.2").style.color = "#E08043";
dlColor = "#E08043"
ulColor = "#E08043";
} else if (dlStatus > 10 && dlStatus < 20) {
result_3_1 = "网络速度:";
result_3_2 = "正常 <br>";
I("testId_3.2").style.color = "#2971BB";
dlColor = "#2971BB"
ulColor = "#2971BB";
} else if (dlStatus >= 20 && dlStatus < 30) {
result_3_1 = "网络速度:";
result_3_2 = "优良 <br>";
I("testId_3.2").style.color = "#4FAC5B";
dlColor = "#4FAC5B"
ulColor = "#4FAC5B";
// result2 = "网络速度:相当于80 ~ 100M宽带,已超越全国83%的网络用户"
} else if (dlStatus >= 30 && dlStatus < 1000) {
result_3_1 = "网络速度:";
result_3_2 = "优良 <br>";
I("testId_3.2").style.color = "#4FAC5B";
dlColor = "#4FAC5B"
ulColor = "#4FAC5B";
// result2 = "网络速度:相当于80 ~ 100M宽带,已超越全国83%的网络用户"
}
I("testId_0").innerHTML = "测试结果:";
I("testId_1.1").innerHTML = result_1_1;
I("testId_1.2").innerHTML = result_1_2;
I("testId_2.1").innerHTML = result_2_1;
I("testId_2.2").innerHTML = result_2_2;
I("testId_3.1").innerHTML = result_3_1;
I("testId_3.2").innerHTML = result_3_2;
frame();
stop_flag = ""
}
if(!aborted){
//if testId is present, show sharing panel, otherwise do nothing
try{
var testId=uiData.testId;
if(testId!=null){
// var shareURL=window.location.href.substring(0,window.location.href.lastIndexOf("/"))+"/results/?id="+testId;
// I("resultsImg").src=shareURL;
// I("resultsURL").value=shareURL;
// I("testId").innerHTML=testId;
// I("shareArea").style.display="";
}
}catch(e){}
}
};
s.start();
}
}
//this function reads the data sent back by the test and updates the UI
function updateUI(forced){
if(!forced&&s.getState()!=3) return;
if(uiData==null) return;
var status=uiData.testState;
// I("ip").textContent=uiData.clientIp;
I("dlText").textContent=(status==1&&uiData.dlStatus==0)?"...":format(uiData.dlStatus);
drawMeter(I("dlMeter"),mbpsToAmount(Number(uiData.dlStatus*(status==1?oscillate():1))),meterBk,dlColor,Number(uiData.dlProgress),progColor);
I("ulText").textContent=(status==3&&uiData.ulStatus==0)?"...":format(uiData.ulStatus);
drawMeter(I("ulMeter"),mbpsToAmount(Number(uiData.ulStatus*(status==3?oscillate():1))),meterBk,ulColor,Number(uiData.ulProgress),progColor);
I("pingText").textContent=format(uiData.pingStatus);
I("jitText").textContent=format(uiData.jitterStatus);
// 新增
drawMeter(I("pingMeter"),msToAmount(Number(uiData.pingStatus*(status==2?oscillate():1))),meterBk,pingColor,Number(uiData.pingProgress),progColor);
I("jitText").textContent=uiData.jitterStatus;
drawMeter(I("jitMeter"),msToAmount(Number(uiData.jitterStatus*(status==2?oscillate():1))),meterBk,jitColor,Number(uiData.pingProgress),progColor);
}
function oscillate(){
return 1+0.02*Math.sin(Date.now()/100);
}
//update the UI every frame
window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||(function(callback,element){setTimeout(callback,1000/60);});
function frame(){
requestAnimationFrame(frame);
updateUI();
}
frame(); //start frame loop
//function to (re)initialize UI
const ip = ""
function initUI(){
drawMeter(I("dlMeter"),0,meterBk,dlColor,0);
drawMeter(I("ulMeter"),0,meterBk,ulColor,0);
drawMeter(I("pingMeter"),0,meterBk,pingColor,0);
drawMeter(I("jitMeter"),0,meterBk,jitColor,0);
I("dlText").textContent="";
I("ulText").textContent="";
I("pingText").textContent="";
I("jitText").textContent="";
I("ip").textContent="";
$.ajax({
async: true,
cache: false,
// url: "http://www.cip.cc/",
// url: "http://api.online-service.vip/ip/me",
// url: "https://nettest.vipkid.com.cn/ip_me",
url: "https://apis.map.qq.com/ws/location/v1/ip",
type: "GET",
// dataType : "text",//指定返回的数据格式
dataType: 'jsonp',
data: {
key: "4JRBZ-2CXE6-NVRSK-ELA57-LA4JH-YGB5Y",
output : "jsonp"
},
success: function(data) {//客户端jquery预先定义好的callback函数,成功获取跨域服务器上的json数据后,会动态执行这个callback函数
console.log("公网出口IP 结果 --->>", data);
ip_me = data.result.ip;
if (ip_me) {
I("ip").textContent="您的IP是: " + ip_me;
I("me_ip").src="https://nettest.vipkid.com.cn/cc/" + ip_me
}
},
error: function(data) {
//jsonp 方式此方法不被触发.原因可能是dataType如果指定为jsonp的话,就已经不是ajax事件了
//请求出错处理
// alert("请求出错(请检查相关度网络状况.)");
console.log("公网出口IP ---->> 请求出错");
}
});
}
</script>
<style type="text/css">
html,body{
border:none; padding:0; margin:0;
background:#FFFFFF;
color:#202020;
}
body{
text-align:center;
/*font-family:"Roboto",sans-serif;*/
font-family: microsoft yahei
}
h1{
color:#404040;
}
#loading{
background-color:#FFFFFF;
color:#404040;
text-align:center;
}
span.loadCircle{
display:inline-block;
width:2em;
height:2em;
vertical-align:middle;
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAP1BMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZyFzwnAAAAFHRSTlMAEvRFvX406baecwbf0casimhSHyiwmqgAAADpSURBVHja7dbJbQMxAENRahnN5lkc//5rDRAkDeRgHszXgACJoKiIiIiIiIiIiIiIiIiIiIj4HHspsrpAVhdVVguzrA4OWc10WcEqpwKbnBo0OU1Q5NSpsoJFTgOecrrdEag85DRgktNqfoEdTjnd7hrEHMEJvmRUYJbTYk5Agy6nau6Abp5Cm7mDBtRdPi9gyKdU7w4p1fsLvyqs8hl4z9/w3n/Hmr9WoQ65lAU4d7lMYOz//QboRR5jBZibLMZdAR6O/Vfa1PlxNr3XdS3HzK/HVPRu/KnLs8iAOh993VpRRERERMT/fAN60wwWaVyWwAAAAABJRU5ErkJggg==');
background-size:2em 2em;
margin-right:0.5em;
animation: spin 0.6s linear infinite;
}
@keyframes spin{
0%{transform:rotate(0deg);}
100%{transform:rotate(359deg);}
}
#startStopBtn{
display:inline-block;
margin:30px;
color: #FFFFFF;
/*background-color: rgba(0,0,0,0);*/
background-color: #f85415;
border:0.15em solid #f85415;
/*color:#6060AA;*/
/*background-color:rgba(0,0,0,0);*/
/*border:0.15em solid #6060FF;*/
border-radius:50em;
transition:all 0.3s;
box-sizing:border-box;
/*width:7em; */
/*height:3em;*/
/*line-height:2.7em;*/
width: 7em;
height: 2.4em;
line-height: 2em;
cursor:pointer;
box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
}
#startStopBtn:hover{
box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
}
#startStopBtn.running{
background-color:#FF3030;
border-color:#FF6060;
color:#FFFFFF;
}
#startStopBtn:before{
content:"开始测速";
}
#startStopBtn.running:before{
content:"强制终止";
}
#serverArea{
margin-top:0em;
}
#server{
font-size:14px;
padding:0.2em;
}
#test{
margin-top:2em;
margin-bottom:12em;
}
div.testArea{
display:inline-block;
width:16em;
height:12.5em;
position:relative;
box-sizing:border-box;
}
div.testArea2{
display:inline-block;
width:14em;
height:7em;
position:relative;
box-sizing:border-box;
text-align:center;
}
div.testArea div.testName{
position:absolute;
top:0.1em; left:0;
width:100%;
font-size:17px;
z-index:9;
}
div.testArea2 div.testName{
display:block;
text-align:center;
font-size:17px;
}
div.testArea div.meterText{
position:absolute;
bottom:1.55em; left:0;
width:100%;
font-size:2.0em;
z-index:9;
}
div.testArea2 div.meterText{
display:inline-block;
font-size:2.0em;
}
div.meterText:empty:before{
content:"0.00";
}
div.testArea div.unit{
position:absolute;
bottom:2em; left:0;
width:100%;
z-index:9;
}
div.testArea2 div.unit{
display:inline-block;
}
div.testArea canvas{
position:absolute;
top:0; left:0; width:100%; height:100%;
z-index:1;
}
div.testGroup{
display:inline-block;
margin: 0 auto;
}
#shareArea{
width:95%;
max-width:40em;
margin:0 auto;
margin-top:2em;
}
#shareArea > *{
display:block;
width:100%;
height:auto;
margin: 0.25em 0;
}
#privacyPolicy{
position:fixed;
top:2em;
bottom:2em;
left:2em;
right:2em;
overflow-y:auto;
width:auto;
height:520px;
box-shadow:0 0 3em 1em #000000;
z-index:999999;
text-align:left;
background-color:#FFFFFF;
padding:1em;
}
a.privacy{
text-align:center;
font-size:0.8em;
color:#808080;
display:block;
}
@media all and (max-width:40em){
body{
font-size:0.8em;
}
}
div.visible{
animation: fadeIn 0.4s;
display:block;
}
div.hidden{
animation: fadeOut 0.4s;
display:none;
}
@keyframes fadeIn{
0%{
opacity:0;
}
100%{
opacity:1;
}
}
@keyframes fadeOut{
0%{
display:block;
opacity:1;
}
100%{
display:block;
opacity:0;
}
}
</style>
<title>IT-网络测速</title>
</head>
<body onload="initServers()">
<!--<h1>IT - 网络测速</h1>-->
<div id="loading" class="visible">
<p id="message"><span class="loadCircle"></span>Selecting a server...</p>
</div>
<div id="testWrapper" class="hidden">
<div id="startStopBtn" onclick="startStop()"></div>
<!-- <a class="privacy" href="#" onclick="I('privacyPolicy').style.display=''">Privacy</a>-->
<div id="serverArea">
<span style="font-size: 15px">
检测项目:
</span> <select id="server" onchange="s.setSelectedServer(SPEEDTEST_SERVERS[this.value])"></select>
</div>
<div id="test">
<div class="testGroup">
<div class="testArea">
<div class="testName">网络延迟</div>
<canvas id="pingMeter" class="meter" ></canvas>
<div id="pingText" class="meterText" ></div>
<div class="unit">ms</div>
</div>
<div class="testArea">
<div class="testName">网络抖动</div>
<canvas id="jitMeter" class="meter"></canvas>
<div id="jitText" class="meterText" ></div>
<div class="unit">ms</div>
</div>
</div>
<div class="testGroup">
<div class="testArea">
<div class="testName">下载</div>
<canvas id="dlMeter" class="meter"></canvas>
<div id="dlText" class="meterText"></div>
<div class="unit">Mbps</div>
</div>
<div class="testArea">
<div class="testName">上传</div>
<canvas id="ulMeter" class="meter"></canvas>
<div id="ulText" class="meterText"></div>
<div class="unit">Mbps</div>
</div>
</div>
<div id="ipArea" style="margin-top: 30px">
<span id="ip"></span>
<a style="font-size: 15px;color: #f85415" class="privacy" href="#" onclick="I('privacyPolicy').style.display=''">查询IP运营商归属</a>
</div>
<div id="shareArea" style="display: none" >
<h3 id="testId_0"></h3>
<p><span id="testId_1.1"></span><span id="testId_1.2"></span>
<span id="testId_2.1"></span><span id="testId_2.2"></span>
<span id="testId_3.1"></span><span id="testId_3.2"></span>
</p>
<!-- <input style="width:400px ;height:128px" type="text" value="" id="resultsURL" readonly="readonly" />-->
</div>
<div style="margin-top: 160px">
<span style="text-align:center;font-size: 8px" href="javascript:;">©2020 VIPKID 网络测速工具V1.0 by IT技术部</span>
</div>
</div>
</div>
<div id="privacyPolicy" style="display:none">
<h4>查询IP运营商信息</h4>
<!-- https://nettest.vipkid.com.cn/cc-->
<div style="margin-top: -350px;">
<iframe id="me_ip" style="width:100%;height:540px;padding-bottom: 40px" scrolling="no" frameborder="0" src="https://nettest.vipkid.com.cn/cc" ></iframe>
<a style="font-size: 14px;color: red;margin-top: 200px" class="privacy" href="#" onclick="I('privacyPolicy').style.display='none'">关闭</a><br/>
</div>
</div>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。