Here is the code snippet to check your internet connection speed (download speed).
Add namespace
using System.Net;
Write code in a Web application on a button click event handler.
- Uri URL = new Uri("http://sixhoej.net/speedtest/1024kb.txt");
- WebClient wc = new WebClient();
- double starttime = Environment.TickCount;
- // download file from the specified URL, and save it to C:\speedtest.txt
- wc.DownloadFile(URL, @"C:\speedtest.txt");
- // get current tickcount
- double endtime = Environment.TickCount;
- // how many seconds did it take?
- // we are calculating this by subtracting starttime from endtime
- // and dividing by 1000 (since the tickcount is in miliseconds.. 1000 ms = 1 sec)
- double secs = Math.Floor(endtime - starttime) / 1000;
- // round the number of secs and remove the decimal point
- double secs2 = Math.Round(secs, 0);
- // calculate download rate in kb per sec.
- // this is done by dividing 1024 by the number of seconds it
- // took to download the file (1024 bytes = 1 kilobyte)
- double kbsec = Math.Round(1024 / secs);
- Label1.Text = "Download rate: " + kbsec + " kb/sec";
- try
- {
- // delete downloaded file
- System.IO.File.Delete(@"C:\speedtest.txt");
- Response.Write("Done.");
- }
- catch
- {
- Response.Write("Couldn't delete download file.");
- Response.Write("To delete the file yourself, go to your C-drive and look for the file 'speedtest.txt'.");
- }

Alireza MahmoudizadePosted Aug 13, 2021, 9:45 AM
That was useful, tnx
Akash PrajapatiPosted May 6, 2021, 5:01 AM
Hello, could you provide, Get internet Speed In MBPS in Below Code? Private Sub CheckSpeed() Dim speeds As Double() = New Double(4) {} For i As Integer = 0 To 4 Dim jQueryFileSize As Integer = 261 'Size of File in KB. Dim client As New WebClient() Dim startTime As DateTime = DateTime.Now client.DownloadFile("http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js", Server.MapPath("~/jQuery.js")) Dim endTime As DateTime = DateTime.Now speeds(i) = Math.Round((jQueryFileSize / (endTime - startTime).TotalSeconds)) Next lblDownloadSpeed.Text = String.Format(": {0} KB/s", speeds.Average()) End Sub
pavel DPosted Apr 13, 2016, 4:31 AM
for what uses double secs2 = Math.Round(secs, 0); if for kbsec U use secs