#!/usr/bin/perl use strict; use warnings; use CGI; my $q = new CGI; my $kbytes = $q->param('datasize') || 100; my @chars = map {chr $_} (0x20 ... 0x7e); my $text; for (my $j = 0; $j < $kbytes * 1000; $j++) { $text .= $chars[int(rand(@chars))]; } $text =~ s/[<>!&]/./g; print $q->header(); print << "EOS" <html> <head> <title>Internet Speed Chacker</title> </head> <body> <h1>Internet Speed Checker</h1> <script Language="JavaScript"> var DataSize = $kbytes; var startTime = new Date().getTime(); </script> <!-- $text --> <script Language="JavaScript"> var endTime = new Date().getTime(); var loadingTime = (endTime - startTime) / 1000; // sec function bps(s, t) { var b = s * 8; // byte to bit var r = b / t; if (r < 10) r = Math.round(r * 10) / 10 else r = Math.round(r); if (r < 1000) return r + " k" else return r / 1000 + " M"; return r; } </script> <table border="1"> <tr> <td>Data Size</td> <td><script>document.write(DataSize)</script> K bytes</td> </tr> <tr> <td>Time</td> <td><script>document.write(loadingTime)</script> sec</td> </tr> <tr> <td>Speed</td> <td><script>document.write(bps(DataSize,loadingTime))</script> bps</td> </tr> </table> <form method="post"> Data Size <select name="datasize" > <option value="100">100</option> <option value="500">500</option> <option value="1000">1000</option> </select> K bytes <input type="submit" value="Check!"> </form> </body> </html> EOS ;