Created
March 15, 2026 05:04
-
-
Save terremoth/0469d579c6438d5a5accabd5b997c2b3 to your computer and use it in GitHub Desktop.
Check website list file, one per line, to se if it is online
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
| param( | |
| [string]$FilePath | |
| ) | |
| if (-not (Test-Path $FilePath)) { | |
| Write-Host "File not found: $FilePath" -ForegroundColor Red | |
| exit | |
| } | |
| $sites = Get-Content $FilePath | |
| foreach ($site in $sites) { | |
| $site = $site.Trim() | |
| if ([string]::IsNullOrWhiteSpace($site)) { | |
| continue | |
| } | |
| if ($site -notmatch '^https?://') { | |
| $url = "http://$site" | |
| } else { | |
| $url = $site | |
| } | |
| try { | |
| $request = [System.Net.HttpWebRequest]::Create($url) | |
| $request.Method = "HEAD" | |
| $request.AllowAutoRedirect = $false | |
| $request.Timeout = 5000 | |
| $response = $request.GetResponse() | |
| $statusCode = [int]$response.StatusCode | |
| if ($statusCode -ge 300 -and $statusCode -lt 400) { | |
| $redirect = $response.Headers["Location"] | |
| Write-Host "$site SUCCESS (REDIRECT to: $redirect)" -ForegroundColor Green | |
| } | |
| elseif ($statusCode -eq 200) { | |
| Write-Host "$site SUCCESS" -ForegroundColor Green | |
| } | |
| else { | |
| Write-Host "$site FAIL" -ForegroundColor Red | |
| } | |
| $response.Close() | |
| } | |
| catch { | |
| try { | |
| if ($site -notmatch '^https?://') { | |
| $url = "https://$site" | |
| $request = [System.Net.HttpWebRequest]::Create($url) | |
| $request.Method = "HEAD" | |
| $request.AllowAutoRedirect = $false | |
| $request.Timeout = 5000 | |
| $response = $request.GetResponse() | |
| $statusCode = [int]$response.StatusCode | |
| if ($statusCode -ge 300 -and $statusCode -lt 400) { | |
| $redirect = $response.Headers["Location"] | |
| Write-Host "$site SUCCESS (REDIRECT to: $redirect)" -ForegroundColor Green | |
| } | |
| elseif ($statusCode -eq 200) { | |
| Write-Host "$site SUCCESS" -ForegroundColor Green | |
| } | |
| else { | |
| Write-Host "$site FAIL" -ForegroundColor Red | |
| } | |
| $response.Close() | |
| } | |
| else { | |
| Write-Host "$site FAIL" -ForegroundColor Red | |
| } | |
| } | |
| catch { | |
| Write-Host "$site FAIL" -ForegroundColor Red | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment