Created
July 13, 2021 19:01
-
-
Save SoulOfUniverse/169f714cd1456ee7c3e0e995d28a0f5f to your computer and use it in GitHub Desktop.
Pinging any target url
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
# First we create the request. | |
$HTTP_Request = [System.Net.WebRequest]::Create('https://google.com') | |
$HTTP_Request.Timeout = 60000 | |
# We then get a response from the site. | |
$HTTP_Response = $HTTP_Request.GetResponse() | |
# We then get the HTTP code as an integer. | |
$HTTP_Status = [int]$HTTP_Response.StatusCode | |
If ($HTTP_Status -eq 200) { | |
Write-Host "Site is up! OK!" -ForegroundColor Cyan | |
} | |
Else { | |
Write-Error "The Site may be down, please check!" | |
} | |
# Finally, we clean up the http request by closing it. | |
If ($HTTP_Response -eq $null) { } | |
Else { $HTTP_Response.Close() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment