Created
April 19, 2016 15:43
-
-
Save cloudflying/793c9991ea6b446eaedc40462873495e to your computer and use it in GitHub Desktop.
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-DNSValid | |
{ | |
[CmdletBinding()] | |
PARAM ($websiteUrl, $company) | |
## Company should be the string value of NETNAME in a ARIN whois lookup. | |
## To find out your value, open http://whois.arin.net/rest/ip/8.8.8.8.txt and copy the value (replace 8.8.8.8 with your IP) | |
## website url can be any DNS resolved value (even internal if using internal DNS system) | |
$primaryResult = Resolve-DnsName -Name $websiteUrl -Type A -DnsOnly; | |
$googResult = Resolve-DnsName -Name $websiteUrl -Type A -Server 8.8.8.8 -DnsOnly; | |
$siteValid = $false; | |
if ($primaryResult.IPAddress = $googResult.IPAddress) { | |
Write-Verbose -Message "Valid IP Address - Matched!" | |
$siteValid = $true; | |
} else { | |
Write-Verbose -Message "Checking ARIN for Valid IP" | |
$checkURI = "http://whois.arin.net/rest/ip/"+$primaryResult.IP4Address+".txt"; | |
$siteCheck = (Invoke-WebRequest -URI $checkURI).content.split([Environment]::NewLine); | |
$siteValid = $siteCheck.Contains($company); | |
Write-Verbose -Message "Valid IP Address - $siteValid" | |
} | |
$Properties = @{ | |
WebsiteUrl = $websiteUrl | |
CompanyName = $company | |
DNSResult = $primaryResult.IPAddress | |
GoogleDNSResult = $googResult.IPAddress | |
Valid = $siteValid | |
} | |
New-Object -TypeName PSobject -Property $Properties | |
} | |
Get-DNSValid -websiteUrl google.com -company GOOGLE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are using MaxRemote Management, you can implement this function by removing the last line and replacing it with the following:
if ((Get-DNSValid -websiteUrl google.com -company GOOGLE).valid = $false) { $intExit=8000;} else { $intExit=0;}