Last active
July 3, 2024 02:17
-
-
Save makotom/4731073 to your computer and use it in GitHub Desktop.
Useless network speed tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define("TESTFILE", "zero"); | |
if(isset($_GET["d"])){ | |
readfile(TESTFILE); | |
exit(); | |
}else if(isset($_GET["n"])){ | |
exit(); | |
} | |
?> | |
<!doctype html> | |
<meta charset="UTF-8"> | |
<title>netspeed</title> | |
<script> | |
(function(){ | |
var netSpeed = {rx : 0, tx : 0}, | |
testdata = "", | |
xhrSpeed = function(url, data, nextStep){ | |
var x = new XMLHttpRequest(), | |
time = 0; | |
x.open("POST", url, true); | |
x.onreadystatechange = function(){ | |
if(x.readyState === 4){ | |
time = new Date().getTime() - time; | |
nextStep(x, time); | |
} | |
}; | |
time = new Date().getTime(); | |
x.send(data); | |
}, | |
getMbps = function(ms, byte){ | |
return ((byte * 8) / (ms / 1000)) / 1000000; | |
}, | |
showNetTime = function(){ | |
alert("RX: " + netSpeed.rx.toString() + " Mbps\nTX: " + netSpeed.tx.toString() + " Mbps"); | |
}, | |
afterTx = function(x, time){ | |
netSpeed.tx = getMbps(time, testdata.length); | |
showNetTime(); | |
}, | |
beforeTx = function(){ | |
xhrSpeed("?n", testdata, afterTx); | |
}, | |
afterRx = function(x, time){ | |
testdata = x.responseText; | |
netSpeed.rx = getMbps(time, testdata.length); | |
beforeTx(x.responseText); | |
}, | |
beforeRx = function(){ | |
if(confirm("Press OK to start")){ | |
xhrSpeed("?d", null, afterRx); | |
} | |
}; | |
addEventListener("click", beforeRx, false); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment