Last active
July 8, 2025 20:28
-
-
Save algonzalez/85021facb24a1093a2a23cee8ea61b3e to your computer and use it in GitHub Desktop.
Call out to various http(s) endpoints to determine if you can access the web.
This file contains hidden or 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 Test-IsOnline { | |
param([Alias('t', 'timeout', 'timeout-secs')][int] $timeout_secs) | |
$urls = 'https://google.com/generate_204', ` | |
'http://google.com/generate_204', ` | |
'https://edge-http.microsoft.com/captiveportal/generate_204', # not sure if MS supports https? | |
'http://edge-http.microsoft.com/captiveportal/generate_204', ` | |
'https://connectivity-check.ubuntu.com', ` | |
'https://connectivity-check.ubuntu.com' | |
$okcodes = '204', '200' # above URLs should always return 204 | |
if ($timeout_secs -lt 0) { $timeout_secs = 0 } | |
foreach ($url in $urls) { | |
$response = $(curl --silent --write-out "%{http_code}" --max-time $timeout_secs $url) | |
if ($response -in $okcodes) { return $true } | |
} | |
return $false | |
} | |
#set-alias isonline Test-IsOnline | |
Test-IsOnline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment