![Wink :wink:](./images/smilies/icon_wink.gif)
SpeedTest_Hackoo_Ookla.bat
I want to share with you this beta version of SpeedTest CLI with Hybrid code Batch-Powershell for testing and optimize it for any bugs.
Code: Select all
<# : Batch Script Section
@rem # The previous line does nothing in Batch, but begins a multiline comment block in PowerShell. This allows a single script to be executed by both interpreters.
@echo off
Title SpeedTest Script Written by Hackoo And Powered by Ookla 2022 & Mode 100,25
@REM OPEN CMD WINDOW MAXIMIZED
@REM IF NOT "%1"=="MAX" START /MAX CMD /D /C "%~0" MAX & GOTO :EOF
cd "%~dp0" & echo %~nx0>"%temp%\MyScriptName.txt"
Color 1B & echo( & Echo(
Echo( Please Wait ... Loading script is in Progress ...
Powershell -executionpolicy bypass -Command "Invoke-Expression $([System.IO.File]::ReadAllText('%~f0'))"
EndLocal
pause
goto:eof
#>
# Powershell Script Section begin here...
# Here we execute our powershell commands...
cls
# https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-win64.zip
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
if($OS_Architecture -eq 'x86')
{
write-host 'Your System is 32-bit. Sorry ! This Program is incompatible under this System !' -fore Red
break
}
else
{
############# Playing Music in Background just for relax and have fun #################
Add-Type -assemblyName PresentationFramework
Function Start-Music {
$code = {
$Radios_Stations_Array = @(
"http://retro.dancewave.online/retrodance.mp3",
"http://www.leeholmes.com/projects/ps_html5/background.mp3",
"http://radio.mosaiquefm.net:8000/mosagold",
"http://radio.mosaiquefm.net:8000/mosadj",
"https://stream.initialradio.fr:8443/djbuzz-192k.mp3",
"http://audio1.maxi80.com"
)
$MyShuffledList = $Radios_Stations_Array | Sort {Get-Random}
$url = $MyShuffledList[1]
$player = New-Object -ComObject 'MediaPlayer.MediaPlayer'
$player.Open($url)
$player
}
$script:ps = [PowerShell]::Create()
$script:player = @($ps.AddScript($code).Invoke())[0]
}
#######################################################################################
Function Stop-Music
{
if ($script:player -ne $null)
{
$script:player.Stop()
Remove-Variable -Name player -Scope script
}
if ($script:ps -ne $null)
{
$script:ps.Runspace.Close()
$script:ps.Dispose()
Remove-Variable -Name ps -Scope script
}
}
###############################################################################################
# Starting to play music while executing the script
Write-Host " Please Wait a while ... SpeedTest is in progress ..." -Fore Yellow
Start-Music
$start_time = Get-Date
###############################################################################################
$Title = "SpeedTest Script Written by Hackoo And Powered by Ookla 2022"
$ErrorActionPreference = "SilentlyContinue"
$Zip_URL = "https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-win64.zip"
$Zip_File = "$env:TEMP\speedtest.zip"
$ExtractPath = "$env:TEMP\SpeedTest"
$SpeedTest_EXE = "$ExtractPath\speedtest.exe"
######################### Create A Shortcut to this Script on Desktop #########################
$MyScriptName = GC "$Env:Temp\MyScriptName.txt"
$MyPath = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($pwd,"$MyScriptName"))
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\SpeedTest.lnk")
$Shortcut.TargetPath = "$MyPath"
$Shortcut.IconLocation = "$SpeedTest_EXE"
$Shortcut.WorkingDirectory = "$([System.IO.Path]::GetFullPath([System.IO.Path]::Combine($pwd,'')))"
$Shortcut.Description = "$Title"
$Shortcut.HotKey = "CTRL+ALT+S"
$Shortcut.Save()
###############################################################################################
# Check if file does not exists , we download and unzip it
if (-not(Test-Path -Path "$Zip_File" -PathType Leaf)) {
Try{$Download = (New-Object System.Net.WebClient).DownloadFile("$Zip_URL","$Zip_File")}
catch {write-host "$_.Exception.Message" -fore Red;Stop-Music;Break;}
unzip "$Zip_File" "$ExtractPath"
}
# Check if file SpeedTest.exe does exists
if (Test-Path -Path "$SpeedTest_EXE" -PathType Leaf) {
$Speedtest = & "$SpeedTest_EXE" --format=json --accept-license --accept-gdpr
$Speedtest | Out-File "$ExtractPath\Last.txt" -Force
$Speedtest = $Speedtest | ConvertFrom-Json
}
[PSCustomObject]$SpeedObject = @{
SSID = (get-netconnectionProfile).Name
ComputerName = $($env:computername)
UserName = $($env:username)
TimeStamp = Get-Date -F "dd/MM/yyyy HH:mm:ss" $Speedtest.timestamp
Downloadspeed = [math]::Round($Speedtest.download.bandwidth / 1000000 * 8, 2)
Uploadspeed = [math]::Round($Speedtest.upload.bandwidth / 1000000 * 8, 2)
Packetloss = [math]::Round($Speedtest.packetLoss)
ISP = $Speedtest.isp
Location = $Speedtest.server.location
Country = $Speedtest.server.Country
ExternalIP = $Speedtest.interface.externalIp
InternalIP = $Speedtest.interface.internalIp
MACAddr = $Speedtest.interface.macAddr
VPN = $Speedtest.interface.isVpn
ServerName = $Speedtest.server.name
UsedServer = $Speedtest.server.host
URLResult = $Speedtest.result.url
Jitter = [math]::Round($Speedtest.ping.jitter)
Latency = [math]::Round($Speedtest.ping.latency)
}
cls
$LogFile = $($SpeedObject.SSID)+"_"+$($env:computername)+"_"+$($env:username)+"_"+"SpeedTest_Results.txt"
$SpeedObject | ConvertTo-Json | Out-File ".\$LogFile" -Append
$SpeedObject
$Elapsed_Time = "$((Get-Date).Subtract($start_time).Minutes) Minutes(M) : $((Get-Date).Subtract($start_time).Seconds) Secondes(s)"
$shell = new-object -comobject "WScript.Shell"
$Answer = $shell.popup("Running Script Time Taken is : $Elapsed_Time `r`nDo you want to launch the result with your default browser ?",0,"$Title",4+32+4096)
If ($Answer -eq 6) {
Write-Host "OK We are Starting the result with your default browser !" -ForegroundColor Yellow -BackgroundColor Blue
ii ".\$LogFile"
Start $SpeedObject.URLResult
$PS_Version=$PSversionTable.PSVersion.Major
If ($PS_Version -ge 2) {$SpeedObject | OGV -Title $Title -Wait}
}
else {
Write-Host "Script Aborted !" -ForegroundColor Yellow -BackgroundColor Blue
ii ".\$LogFile"
}
Stop-Music
}