Browse Source

Fix getzig test-connection for powershell desktop

master
Julian Noble 4 months ago
parent
commit
233a71ca43
  1. 45
      bin/getzig.cmd
  2. 45
      src/scriptapps/getzig.ps1

45
bin/getzig.cmd

@ -931,27 +931,50 @@ if ($mirrors_response.StatusCode -eq 200) {
$hostname = $uri.Host
$dict_mirrors[$hostname] = @{}
$dict_mirrors[$hostname]["uri"] = $mirror
$dict_mirrors[$hostname]["latency"] = 888888 ;#default
$host_list += $hostname
#write-host "Host name: $hostname"
}
#write-host "dict: $($dict_mirrors | out-String)"
write-host "host_list: $host_list"
$test_results = Test-Connection -TargetName $host_list -Count 1 -Ipv4 -Detailed -TcpPort 443 -Quiet
for ($i = 0; $i -lt $test_results.Count; $i++) {
$result = $test_results[$i]
if ($result) {
$targethost = $result.Target
if ($result.Status -eq "Success") {
$dict_mirrors[$targethost]["latency"] = $result.Latency
if ($PSVersionTable.PSEdition -eq "Desktop") {
#powershell.exe
#we seem to need -ErrorAction Ignore for bad/unresponsive host entries - but unlike with pwsh, we don't get any corresponding entry in the test_results, and -Quiet doesn't seem to give us results either REVIEW
$test_results = Test-Connection $host_list -Count 1 -ErrorAction Ignore
for ($i = 0; $i -lt $test_results.Count; $i++) {
$result = $test_results[$i]
if ($result) {
$targethost = $result.Address
if ($result.StatusCode -eq 0) {
$dict_mirrors[$targethost]["latency"] = $result.ResponseTime
} else {
$dict_mirrors[$targethost]["latency"] = 999999
}
} else {
$targethost = $host_list[$i]
$dict_mirrors[$targethost]["latency"] = 999999
}
} else {
$targethost = $host_list[$i]
$dict_mirrors[$targethost]["latency"] = 999999
}
} else {
#pwsh.exe
$test_results = Test-Connection -TargetName $host_list -Count 1 -Ipv4 -Detailed -TcpPort 443 -Quiet
for ($i = 0; $i -lt $test_results.Count; $i++) {
$result = $test_results[$i]
if ($result) {
$targethost = $result.Target
if ($result.Status -eq "Success") {
$dict_mirrors[$targethost]["latency"] = $result.Latency
} else {
$dict_mirrors[$targethost]["latency"] = 999999
}
} else {
$targethost = $host_list[$i]
$dict_mirrors[$targethost]["latency"] = 999999
}
}
}
$list_mirror_dicts = @()
#write-host "dict tested: $($dict_mirrors | Out-String)"
foreach ($key in $dict_mirrors.Keys) {

45
src/scriptapps/getzig.ps1

@ -97,27 +97,50 @@ if ($mirrors_response.StatusCode -eq 200) {
$hostname = $uri.Host
$dict_mirrors[$hostname] = @{}
$dict_mirrors[$hostname]["uri"] = $mirror
$dict_mirrors[$hostname]["latency"] = 888888 ;#default
$host_list += $hostname
#write-host "Host name: $hostname"
}
#write-host "dict: $($dict_mirrors | out-String)"
write-host "host_list: $host_list"
$test_results = Test-Connection -TargetName $host_list -Count 1 -Ipv4 -Detailed -TcpPort 443 -Quiet
for ($i = 0; $i -lt $test_results.Count; $i++) {
$result = $test_results[$i]
if ($result) {
$targethost = $result.Target
if ($result.Status -eq "Success") {
$dict_mirrors[$targethost]["latency"] = $result.Latency
if ($PSVersionTable.PSEdition -eq "Desktop") {
#powershell.exe
#we seem to need -ErrorAction Ignore for bad/unresponsive host entries - but unlike with pwsh, we don't get any corresponding entry in the test_results, and -Quiet doesn't seem to give us results either REVIEW
$test_results = Test-Connection $host_list -Count 1 -ErrorAction Ignore
for ($i = 0; $i -lt $test_results.Count; $i++) {
$result = $test_results[$i]
if ($result) {
$targethost = $result.Address
if ($result.StatusCode -eq 0) {
$dict_mirrors[$targethost]["latency"] = $result.ResponseTime
} else {
$dict_mirrors[$targethost]["latency"] = 999999
}
} else {
$targethost = $host_list[$i]
$dict_mirrors[$targethost]["latency"] = 999999
}
} else {
$targethost = $host_list[$i]
$dict_mirrors[$targethost]["latency"] = 999999
}
} else {
#pwsh.exe
$test_results = Test-Connection -TargetName $host_list -Count 1 -Ipv4 -Detailed -TcpPort 443 -Quiet
for ($i = 0; $i -lt $test_results.Count; $i++) {
$result = $test_results[$i]
if ($result) {
$targethost = $result.Target
if ($result.Status -eq "Success") {
$dict_mirrors[$targethost]["latency"] = $result.Latency
} else {
$dict_mirrors[$targethost]["latency"] = 999999
}
} else {
$targethost = $host_list[$i]
$dict_mirrors[$targethost]["latency"] = 999999
}
}
}
$list_mirror_dicts = @()
#write-host "dict tested: $($dict_mirrors | Out-String)"
foreach ($key in $dict_mirrors.Keys) {

Loading…
Cancel
Save