Last active
December 12, 2017 17:48
-
-
Save yorgabr/dc1292d76d2fb765bba1972bf696139c to your computer and use it in GitHub Desktop.
Use this small script to come across the fastest Cygwin Setup mirror for your location.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function purge-any-pending-job {Get-Job | Remove-Job} | |
$measure_mirror_latency = { | |
Param([string] $argument) | |
$mirror_url = ($argument -split ";")[0] | |
$sum_url = "$($mirror_url)x86_64/sha512.sum" | |
$req = [System.Net.WebRequest]::Create($sum_url) | |
$req.Timeout = 2000 | |
try { | |
$dur = (Measure-Command { | |
$res = $req.getResponse() | |
}).TotalSeconds | |
} | |
catch [Exception] { | |
$dur = "unreachable" | |
} | |
Write-Output "$dur`t$mirror_url" | |
} | |
# Become proxy aware. | |
(New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials | |
[Environment]::SetEnvironmentVariable("NO_PROXY", "127.0.0.1", "User") | |
# Parallel measure each mirror latency. | |
purge-any-pending-job | |
$max_threads = (Get-WmiObject -Class win32_processor).NumberOfCores | |
$mirrors = ((wget https://cygwin.com/mirrors.lst).Content -split "`n") | |
$total = $mirrors.Count | |
$jobs_count = 0 | |
foreach($mirror in $mirrors){ | |
if($mirror.Length -eq 0){continue} | |
Start-Job -Scriptblock $measure_mirror_latency -ArgumentList $mirror | Out-Null | |
$jobs_count++ | |
Write-Progress -Activity "Verifying all mirrors..." -PercentComplete (100 * $jobs_count / $total) | |
While ($(Get-Job -state running).count -ge $max_threads){ | |
Start-Sleep -Milliseconds 30 | |
} | |
} | |
# Wait for all measuring jobs to finish. | |
While ($(Get-Job -State Running).count -gt 0){ | |
Start-Sleep -Milliseconds 100 | |
} | |
# Get each measure results. | |
$results = @() | |
$jobs = Get-Job | |
foreach($job in $jobs){ | |
$result = Receive-Job -Id ($job.Id) | |
$results += $result | |
} | |
purge-any-pending-job | |
# Return the fastest mirror. | |
(($results | Sort-Object)[0] -split "`t")[1] | |
Hum... Dá para usar em ambientes "hostis" de rede? ;)
Acabei de olhar o MobaXterm... UAU! Muito obrigado pela dica!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
já tentou usar o mobaxterm?