From a42aaf1e5610671d6302af765db003ea9c3b8306 Mon Sep 17 00:00:00 2001 From: bbrendon Date: Sat, 1 Jun 2024 14:11:27 -0700 Subject: [PATCH 1/2] Update Win_Speedtest.ps1 --- scripts/Win_Speedtest.ps1 | 59 +++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/scripts/Win_Speedtest.ps1 b/scripts/Win_Speedtest.ps1 index 2eb02c23..03c41826 100644 --- a/scripts/Win_Speedtest.ps1 +++ b/scripts/Win_Speedtest.ps1 @@ -1,3 +1,4 @@ + ## Measures the speed of the download, can only be ran on a PC running Windows 10 or a server running Server 2016+, plan is to add uploading also ## Majority of this script has been copied/butchered from https://www.ramblingtechie.co.uk/2020/07/13/internet-speed-test-in-powershell/ # MINIMUM ACCEPTED THRESHOLD IN mbps @@ -5,23 +6,55 @@ $mindownloadspeed = 20 $minuploadspeed = 4 # File to download you can find download links for other files here https://speedtest.flonix.net -$downloadurl = "https://files.xlawgaming.com/10mb.bin" -#$UploadURL = "http://ipv4.download.thinkbroadband.com/10MB.zip" +$downloadurls = @( + "https://files.xlawgaming.com/10mb.bin", + "https://raw.githubusercontent.com/jamesward/play-load-tests/master/public/10mb.txt" +) # SIZE OF SPECIFIED FILE IN MB (adjust this to match the size of your file in MB as above) -$size = 10 +$sizes = @( + 10, + 10 +) + # Name of Downloaded file $localfile = "SpeedTest.bin" # WEB CLIENT VARIABLES $webclient = New-Object System.Net.WebClient -#RUN DOWNLOAD & CALCULATE DOWNLOAD SPEED -$downloadstart_time = Get-Date -$webclient.DownloadFile($downloadurl, $localfile) -$downloadtimetaken = $((Get-Date).Subtract($downloadstart_time).Seconds) -$downloadspeed = ($size / $downloadtimetaken) * 8 -Write-Output "Time taken: $downloadtimetaken second(s) | Download Speed: $downloadspeed mbps" +# Variable to track if download was successful +$downloadSuccessful = $false + +for ($i = 0; $i -lt $downloadurls.Length; $i++) { + $downloadurl = $downloadurls[$i] + $size = $sizes[$i] + + # Write-Output "trying $downloadurl" + try { + #RUN DOWNLOAD & CALCULATE DOWNLOAD SPEED + $start_time = Get-Date + # $a = Measure-Command -Expression { + $webclient.DownloadFile($downloadurl, $localfile) + # } + $end_time = Get-Date + $downloadSuccessful = $true + break # exits for loop + } catch { + Write-Output "Failed to download: $downloadurl : Trying the next URL..." + } +} + +if (-not $downloadSuccessful) { + Write-Output "All download attempts failed." + exit 1 +} + + +$secs_taken = ($end_time - $start_time).TotalSeconds +$downloadspeed = ($size / $secs_taken) * 8 +Write-Output "Time taken: $([Math]::Round($secs_taken, 2)) seconds | Download Speed: $([Math]::Round($downloadspeed, 2)) mbps" + #RUN UPLOAD & CALCULATE UPLOAD SPEED #$uploadstart_time = Get-Date @@ -35,11 +68,9 @@ Remove-Item -path $localfile #SEND ALERTS IF BELOW MINIMUM THRESHOLD if ($downloadspeed -ge $mindownloadspeed) { - Write-Output "Speed is acceptable. Current download speed at is $downloadspeed mbps which is above the threshold of $mindownloadspeed mbps" + Write-Output "Speed is acceptable. Current download speed is above the threshold of $mindownloadspeed mbps" exit 0 -} - -else { - Write-Output "Current download speed at is $downloadspeed mbps which is below the minimum threshold of $mindownloadspeed mbps" +} else { + Write-Output "Current download speed is below the minimum threshold of $mindownloadspeed mbps" exit 1 } From 484743af4a0b4321d5077a5eb138f7c14c76f508 Mon Sep 17 00:00:00 2001 From: Dan <7434746+wh1te909@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:48:47 -0700 Subject: [PATCH 2/2] remove dead url --- scripts/Win_Speedtest.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/Win_Speedtest.ps1 b/scripts/Win_Speedtest.ps1 index 03c41826..5717d069 100644 --- a/scripts/Win_Speedtest.ps1 +++ b/scripts/Win_Speedtest.ps1 @@ -7,7 +7,6 @@ $minuploadspeed = 4 # File to download you can find download links for other files here https://speedtest.flonix.net $downloadurls = @( - "https://files.xlawgaming.com/10mb.bin", "https://raw.githubusercontent.com/jamesward/play-load-tests/master/public/10mb.txt" )