Skip to content

Instantly share code, notes, and snippets.

@SQLtattoo
Last active November 2, 2021 08:33
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 SQLtattoo/3ff38a177f10249abc378767d82edbfd to your computer and use it in GitHub Desktop.
Save SQLtattoo/3ff38a177f10249abc378767d82edbfd to your computer and use it in GitHub Desktop.
PowerShell loop for DNS name lookup until resolved.
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