Last active
November 2, 2021 08:33
-
-
Save SQLtattoo/3ff38a177f10249abc378767d82edbfd to your computer and use it in GitHub Desktop.
PowerShell loop for DNS name lookup until resolved.
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
while(1 -eq 1) { | |
#get the IP of the domain assigned, by using the Cloudflare DNS server or replace with any other | |
$ip = Resolve-DnsName -Name <domain_name_here e.g. www.github.com> -Server 1.1.1.1 -Type A -ErrorAction SilentlyContinue -ErrorVariable procErr | |
#if there was an error then print a warning message | |
if($procErr){ | |
Write-Warning "Not resolved!" | |
} | |
#if the IP is not null, means it was resolved successfully | |
if($ip -ne $null){ | |
#get the date and time that the resolution started working on | |
break #exit the loop and show the result | |
Write-Host "Worked on: " (Get-Date) "(IP:" $ip.Address ")" | |
} | |
#it seem the resolve did not happen, wait for 5 minutes and check again | |
Start-Sleep -s 300 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment