Skip to content

Instantly share code, notes, and snippets.

@grantcarthew
Created July 29, 2019 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantcarthew/6c83bd4d82a71fb602e391fe6d84742c to your computer and use it in GitHub Desktop.
Save grantcarthew/6c83bd4d82a71fb602e391fe6d84742c to your computer and use it in GitHub Desktop.
$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
}
@grantcarthew
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment