Created
April 6, 2014 18:44
-
-
Save devnoname120/10009977 to your computer and use it in GitHub Desktop.
Cygwin Mirror Tester
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
;#NoTrayIcon | |
#include <WinHttp.au3> | |
#include <String.au3> | |
#include <array.au3> | |
$mirrorsUrl = "http://cygwin.com/mirrors.lst" | |
$aMirrorsUrl = StringSplit($mirrorsUrl, "/", 2) | |
$mirrorsHost = $aMirrorsUrl[2] | |
$mirrorsFile = $aMirrorsUrl[3] | |
$testFile = "x86/setup.ini" | |
$hOpen = _WinHttpOpen() | |
$hConnect = _WinHttpConnect($hOpen, $mirrorsHost) | |
$hRequest = _WinHttpOpenRequest($hConnect, Default, $mirrorsFile) | |
; Send request | |
_WinHttpSendRequest($hRequest) | |
; Wait for the response | |
_WinHttpReceiveResponse($hRequest) | |
global $sChunk | |
If _WinHttpQueryDataAvailable($hRequest) Then | |
Local $sData | |
While 1 | |
$sChunk = _WinHttpReadData($hRequest) | |
If @error Then ExitLoop | |
$sData &= $sChunk | |
WEnd | |
_WinHttpCloseHandle($hRequest) | |
_WinHttpCloseHandle($hConnect) | |
_WinHttpCloseHandle($hOpen) | |
$tmpMirrors = Stringsplit($sData, @CRLF) | |
;_ArrayDisplay($tmpMirrors) | |
global $aMirrors[1] | |
for $i=1 To Ubound($tmpMirrors) - 1 | |
$currMirror = _StringBetween($tmpMirrors[$i], "http://",";") | |
If @error = 1 Then ContinueLoop | |
; Delete the last character if "/" | |
If StringRight($currMirror[0],1) = "/" Then $currMirror[0] = StringMid($currMirror[0], 1, StringLen($currMirror[0]) - 1) | |
If $i = 1 Then | |
$aMirrors[0] = $currMirror[0] | |
Else | |
_ArrayAdd($aMirrors, $currMirror[0]) | |
EndIf | |
Next | |
global $aGoodMirrors[1][2] | |
for $i=0 To Ubound($aMirrors) - 1 | |
$currMirror = $aMirrors[$i] | |
$hOpen = _WinHttpOpen() | |
$reqStart = TimerInit() | |
Local $sitePathOffset = StringInStr($currMirror, "/", 0, 1) | |
Local $realAddress, $extrapath | |
If $sitePathOffset <> 0 Then | |
$realAddress = StringMid($currMirror, 1, $sitePathOffset - 1) | |
$extraPath = StringMid($currMirror, $sitePathOffset + 1) | |
EndIf | |
If $sitePathOffset <> 0 Then $currMirror = $realAddress | |
$hConnect = _WinHttpConnect($hOpen, $currMirror) | |
Local $currFile | |
If $sitePathOffset <> 0 Then | |
$currFile = $extraPath & "/" & $testFile | |
Else | |
$currFile = $testFile | |
EndIf | |
$hRequest = _WinHttpOpenRequest($hConnect, Default, $currFile) | |
_WinHttpSendRequest($hRequest) | |
; Wait for the response | |
_WinHttpReceiveResponse($hRequest) | |
; There is some content to get (We should also verify size) | |
If _WinHttpQueryDataAvailable($hRequest) Then | |
While 1 | |
; Download data but do not keep it (useless) | |
_WinHttpReadData($hRequest) | |
If @error Then ExitLoop | |
WEnd | |
_WinHttpCloseHandle($hRequest) | |
_WinHttpCloseHandle($hConnect) | |
_WinHttpCloseHandle($hOpen) | |
Else | |
ContinueLoop | |
EndIf | |
$reqDiff = TimerDiff($reqStart) | |
ConsoleWrite("Time: " & $reqDiff & @CRLF & "Mirror: " & $currMirror & @CRLF) | |
; If the array is yet empty | |
If $aGoodMirrors[0][0] = "" Then | |
$aGoodMirrors[0][0] = $reqDiff | |
$aGoodMirrors[0][1] = $currMirror | |
Else | |
$latestArraySize = Ubound($aGoodMirrors) | |
Redim $aGoodMirrors[$latestArraySize + 1][2] | |
$aGoodMirrors[$latestArraySize][0] = $reqDiff | |
$aGoodMirrors[$latestArraySize][1] = $currMirror | |
EndIf | |
Next | |
$aGoodMirros = _Arraysort($aGoodMirrors) | |
; Display sorted results | |
_ArrayDisplay($aGoodMirrors, "Cygwin Mirror Tester - Fastest mirror on the top", -1, 0, "", "|", "Rank|Time (ms)|HTTP Mirror") | |
EndIf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cygwin Mirror Tester
Description
This AutoIt3 code will retrieve all the available Cygwin HTTP mirrors, try to download the file "x86/setup.ini" using each mirror, it then displays a sorted list with the time it took to download this file.
Depending on the speed of your Internet connection, this can take time before the summary window opens.
The fastest mirror is on the top of the list, the slowest is at the bottom.
This comes useful when you want to download Cygwin in the minimal time.
Screenshot
Download
Compiled EXE can be downloaded here: http://www.mirari.fr/MgeV
License
WTFPL