1 | 1 | simandl | #!/usr/bin/perl |
2 | | | # |
3 | | | ############################################## |
4 | | | # BanderDyn |
5 | | | ############################################## |
6 | | | # Simple script for measuring download |
7 | | | # speed, with some dynamical ability |
8 | | | # to end up as soon as 10s are crossed. |
9 | | | # |
10 | | | # It's time precision is 1s - |
11 | | | # we only relay on system time ability |
12 | | | # and are not using require 'sys/syscall.ph'; |
13 | | | # http://www.perldoc.com/perl5.8.0/pod/perlfaq8.html |
14 | | | # |
15 | | | # Bander, maintenance: Adam Pribyl, covex@ahoj.fsik.cvut.cz |
16 | | | # Dyn: Petr Simandl, www.simandl.cz |
17 | | | ############################################### |
18 | | | |
19 | 2 | simandl | use Time::HiRes; |
20 | | | |
21 | 1 | simandl | print "Content-type: text/html\n\n"; |
22 | | | |
23 | 2 | simandl | print "<HTML><HEAD><META HTTP-EQUIV=Pragma CONTENT=no-cache>"; |
24 | | | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></HEAD><BODY>\n"; # nocache! |
25 | 1 | simandl | |
26 | 2 | simandl | $kb = 50*1024; |
27 | | | @nkbp = (10,20,70,100,300,500); |
28 | 1 | simandl | $nkb = 0; |
29 | | | $lnkbp = $#nkbp; |
30 | | | |
31 | 2 | simandl | @pism = ("aaaaaaaaaa","bbbbbbbbbb","cccccccccc","dddddddddd","eeeeeeeeee","ffffffffff"); |
32 | 1 | simandl | |
33 | | | $svrtimeout = 30; # httpd server timeout in seconds |
34 | | | |
35 | | | $testtime = 10; # maximum test time |
36 | | | |
37 | | | $lospd = $nkbp[0]/$svrtimeout; |
38 | | | |
39 | 2 | simandl | print "<CENTER>\n"; |
40 | | | printf "Pokud se VĂĄm po chvilce nezobrazĂ namÄĹenĂĄ rychlost, tak mĂĄte pomalĂŠ pĹipojenĂ (< %1.2f kiB/s) a nebo zaruĹĄenĂŠ pĹipojenĂ. <br>\n", $lospd; |
41 | 1 | simandl | |
42 | 2 | simandl | print "OdeslĂĄno"; |
43 | 1 | simandl | |
44 | 2 | simandl | $tm2 = 0; |
45 | | | $tm1 = [ Time::HiRes::gettimeofday( ) ]; |
46 | 1 | simandl | |
47 | | | for ($ii = 0; $ii <= $lnkbp; $ii++) { |
48 | 2 | simandl | if ( $tm2 < $testtime ) |
49 | 1 | simandl | { |
50 | 2 | simandl | $numkb=$nkbp[$ii]; |
51 | | | for ($f = 1; $f <= $numkb; $f++) { |
52 | 1 | simandl | print "<!--"; |
53 | 2 | simandl | for ($g = 1; $g <= (($kb-10)/50) ; $g++) { print "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee"; } |
54 | 1 | simandl | print "-->. \n"; |
55 | | | } |
56 | 2 | simandl | $tm2 = Time::HiRes::tv_interval( $tm1 ); |
57 | 1 | simandl | $nkb = $nkb + $nkbp[$ii]; |
58 | 2 | simandl | printf "%.2f MiB", $nkb * $kb/1000000; |
59 | 1 | simandl | } |
60 | | | } |
61 | | | |
62 | | | print "<br>\n"; |
63 | | | |
64 | | | $adresa = "$ENV{'REMOTE_ADDR'}"; |
65 | | | $server = "$ENV{'SERVER_NAME'}"; |
66 | | | |
67 | | | print "\n<P>"; |
68 | 2 | simandl | $time = ($tm2); |
69 | | | $numMb = $nkb * $kb/1000024; |
70 | | | printf "OdeslĂĄno %.2f MiB ze serveru $server na IP adresu $adresa za %.2f sekund<br />\n", $numMb, $time; |
71 | | | print "PĹibliĹžnĂĄ rychlost stahovĂĄnĂ VaĹĄeho pĹipojenĂ je: "; |
72 | | | $speed = $nkb*$kb/$tm2; |
73 | | | $speedkb = $speed/1024; |
74 | | | $speedkbps = 8*$speed/1024; |
75 | | | printf "%.2f B/s = %.2f kiB/s = %.2f Mib/s\n", $speed, $speedkb, $speedkbps/1000; |
76 | | | |
77 | | | printf "<h3>VaĹĄe rychlost stahovĂĄnĂ ze serveru $server je %.2f MegabitĹŻ za sekundu</h3>\n", $speedkbps/1000; |
78 | 1 | simandl | $date = `date`; |
79 | 2 | simandl | print "$date\n<BR />"; |
80 | | | print "<A HREF=\"http://bbs.cvut.cz/~covex/czfree/index.html\#bander\">Bander speed test</A>\n"; |
81 | 1 | simandl | |
82 | 2 | simandl | print "</center></BODY></HTML>"; |