Created
February 20, 2014 22:37
-
-
Save Nora-Ballard/9124761 to your computer and use it in GitHub Desktop.
Functions for testing internet connectivity. Uses the Microsoft NCSI by default, but anything can be passed by parameter.
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
function Get-ExternalIP | |
{ | |
$URL = 'http://ifconfig.me/all.xml' | |
$ProxyURL = [System.Net.WebRequest]::GetSystemWebProxy().GetProxy($URL).AbsoluteUri | |
$resp = Invoke-WebRequest -Uri $URL -Method Get -Proxy $ProxyURL -ProxyUseDefaultCredentials | |
$([xml]$resp).info.ip_addr | |
} | |
function Test-InternetConnection | |
{ | |
param( | |
[string]$URL = 'http://www.msftncsi.com/ncsi.txt' | |
) | |
$Proxy = [System.Net.WebRequest]::GetSystemWebProxy().GetProxy($URL) | |
try { | |
if ($Proxy.OriginalString -eq $URL) { $HTTPResponse = Invoke-WebRequest -Uri $URL -Method Get } | |
else { $HTTPResponse = Invoke-WebRequest -Uri $URL -Method Get -Proxy $Proxy.AbsoluteUri -ProxyUseDefaultCredentials} | |
} | |
catch { $HTTPResponse = $null } | |
if ($HTTPResponse.StatusDescription -eq 'OK') {$True} else {$False} | |
} | |
function Test-DNSResolution | |
{ | |
param( | |
[string]$Name = 'www.msftncsi.com' | |
) | |
try { $DNSResponse = [System.Net.Dns]::GetHostEntry($Name) } | |
catch { $DNSResponse = $null } | |
If ($DNSResponse) { $True } else { $false } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment