top of page

PowerShell - IP to HostName resolve from text list

  • Writer: Jon Boyette
    Jon Boyette
  • Jan 10, 2022
  • 1 min read

Save as a named .ps1. This is the IP to host versus the latter, this one becomes invaluable if doing any traceroute items and need to list IP's out to resolve.

# Get list from file, initialize empty array


$ListOfIPs=Get-content "c:\temp\IPs.txt"

$ResultList = @()


# roll through the list, resolving as we

# go with the .Net DNS resolver


foreach ($IP in $ListOfIPs)

{

# We don't want to see any errors as we go, right?


$ErrorActionPreference = "silentlycontinue"

$Result = $null


# status to user, just so they know that something

# is still happening, then pass the current IP

# to .Net for name resolution.


write-host "resolving $IP"

$result = [System.Net.Dns]::gethostentry($IP)



# Enter into the array, with the returned results.


If ($Result)

{

$ResultList += "$IP," + [string]$Result.HostName

}

Else

{

$ResultList += "$IP,unresolved"

}

}


# send it out to a file, and inform the user we are done


$ResultList | Out-File c:\temp\IPsresolved.txt

write-host "name resolution complete"



 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page