Created
July 29, 2019 00:48
-
-
Save grantcarthew/6c83bd4d82a71fb602e391fe6d84742c to your computer and use it in GitHub Desktop.
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
$logPath = 'D:\Temp\github-ping.log' | |
$title = "Script started at " + (Get-Date) | |
Set-Content -Value $title -Path $logPath | |
Write-Host -Object $title | |
$ip = 'Error' | |
$logIt = $false | |
$count = 0 | |
$result = $null | |
$newResult = $null | |
$newIp = $null | |
$start = Get-Date -Format hh:mm:ss | |
$initial = $true | |
while ($true) { | |
try { | |
$resolve = Resolve-DnsName -Name github.com | |
$newIp = $resolve[0].IPAddress | |
if ($ip -ne $newIp) { | |
$ip = $newIp | |
$logIt = $true | |
} | |
$res = Invoke-WebRequest -Uri 'http://github.com' | |
$newResult = 'Succeeded' | |
} | |
catch { | |
$newResult = 'Failed' | |
} | |
if ($result -ne $newResult) { | |
$logIt = $true | |
$result = $newResult | |
} | |
if ($logIt -and !$initial) { | |
$count = 0 | |
$start = Get-Date -Format hh:mm:ss | |
Add-Content -Value $message -Path D:\Temp\github-ping.log | |
} | |
$count++ | |
$message = "HTTP:[github.com] Start:[$start] Time:[$(Get-Date -Format hh:mm:ss)] IP:[$ip] Result:[$result] Count: [$count]" | |
Write-Host -Object $message | |
$initial = $false | |
$newIp = $null | |
$newResult = 'Failed' | |
$logIt = $false | |
Start-Sleep -Seconds 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had internet issues at home and this script helped me to discover the issue. GitHub was being served via three public IP addresses and only one was working. The source of the issue was the local service provider routing.