-
-
Notifications
You must be signed in to change notification settings - Fork 17
44 lines (42 loc) · 1.69 KB
/
check-cygwin-mirrors.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
name: Check Cygwin mirrors
on:
workflow_dispatch:
jobs:
check-mirrors:
name: Check Cygwin mirrors
runs-on: windows-latest
steps:
-
name: Check
run: |
$list = $(Invoke-WebRequest -Uri https://cygwin.com/mirrors.lst).ToString()
$lines = $list -split "`r`n|`n"
$hosts = @()
foreach ($line in $lines) {
if (-not($line)) {
continue
}
$url, $name, $continent, $country, $flag = $line -split ';'
$match = Select-String -InputObject $url -Pattern '^(?<proto>https?)://(?<host>[^:/]+)(?<port>:\d+)?($|/)'
if (-not($match)) {
continue
}
if ($match.Matches[0].Groups['port'] -and $match.Matches[0].Groups['port'].Value) {
$port = $match.Matches[0].Groups['port'].Value
} else {
$port = $match.Matches[0].Groups['proto'].Value -eq 'http' ? 80 : 443;
}
try {
$conn = Test-Connection -TargetName $match.Matches[0].Groups['host'].Value -Count 1 -TimeoutSeconds 1 -TcpPort $port -Detailed
} catch {
$conn = $null
}
if ($conn -and $conn.Status -eq 'Success') {
$latency = $conn.Latency
} else {
$latency = $null
}
$hosts += [pscustomobject] @{'Url' = $url; 'Latency' = $latency; 'Continent' = $continent; 'Country' = $country}
}
$hosts = $hosts | Sort-Object -Property @{Expression={if ($_.Latency -eq $null) { [int]::MaxValue } else { $_.Latency }}}, 'Url'
$hosts