Ookla Speedtest


Recommended Posts

After a few failed attempts to get this working on Windows via Powershell (works, but too inaccurate), I punted and used speedtest-cli.  If I can replicate that into Groovy, then perhaps it could be universal, but Linux-only for now.


This will be held for code review, but it is very simple code :).

Link to comment
Share on other sites

  • 2 months later...

@Cole McDonald Sure, no problem -- see below.  The Ookla one is not much better in reality because the web method is not as accurate as the application socket method, but at least it tried to do bidirectional testing.

I can't claim credit for this, I found it and modified a bit to work in LM.  I set the mirror site as a property since auto-selection does not work with testmy.net.



$size = 50;
$mirror = "##speedtest.testmy.mirror##";
if ($site -eq "") {
    $url = "https://testmy.net/dl-${size}MB"
else {
    $url = "https://${mirror}.testmy.net/dl-${size}MB"
$path = "Out-Null"
$WebClient = New-Object System.Net.WebClient 
$mbps = "{0:N2}" -f (($size/(Measure-Command {$Request=Get-Date; $WebClient.DownloadFile( $url, $path )}).TotalSeconds) * 😎
Write-Host "Mbps="$mbps

Link to comment
Share on other sites

I wonder if I could dig up some powershell/.net to implement a socket we could push the test through... let me search through my saved favorites, I think I've used something like that to instantiate remote listeners for port route verification... https://stackoverflow.com/questions/29759854/how-to-connect-to-tcp-socket-with-powershell-to-send-and-receive-data

I'm also testing invoke-webrequest -URI $URL right now as well using the URI from your code against dallas7.  I'll see what it returns and if I can get that parsed to the value you're looking for.

Link to comment
Share on other sites

$stats = Measure-Command {$return = Invoke-WebRequest -Uri "https://dallas7.testmy.net/dl-10MB"}

Seems to work to get the same data as the .net web client the other is implementing.  This both implements the download test and retrieves the returned code to be parsed for any tokens that would allow it to perform the push... just have to figure out the request they're building to piece the next URL or REST request together.

Link to comment
Share on other sites

1 hour ago, mnagel said:

$size          = 50
$mirror        = "##speedtest.testmy.mirror##"

if ( $mirror -eq "" ) {
    $url       = "https://testmy.net/dl-${ $size }MB"
} else {
    $url       = "https://${ mirror }.testmy.net/dl-${ $size }MB"

$timer         = Measure-Command { $response = invoke-webrequest -uri $url }
$result        = ( $size / ( $timer ).TotalSeconds ) * B
$mbps          = "{0:N2}" -f ( $result )

Write-Host "Mbps=$mbps"



I changed the first If () {} to test the correct variable (was $site, which isn't represented anywhere else in the script).  Then I cleaned the code up a bit and lined everything up... OCD is both great and horrible for programming.

Edited by Cole McDonald
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.