Skip to content

Instantly share code, notes, and snippets.

@cloudflying
Created April 19, 2016 15:43
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 cloudflying/793c9991ea6b446eaedc40462873495e to your computer and use it in GitHub Desktop.
Save cloudflying/793c9991ea6b446eaedc40462873495e to your computer and use it in GitHub Desktop.
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
@cloudflying
Copy link
Author

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;}

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