How to retrieve the computer name based on the IP?

this mechanism is called “reverse lookup”. In general it works if your DNS server contain “reverse zones” and reverse records.

In that case, the following commands works fine:

ping -a <IP>

nslookup -a <IP>

But if your internal DNS Server, does not contain reverse zone. You must request records from your DNS server directly.

To achieve that, you can use nslookup or powershell to get an answer from a DNS server:

a) using nslookup


server <enter remote DNS>

<type the IP>


b) using Powershell

# Get DNS records (computer FQDN) based on list of IPs (input)
# Created    :     10/01/2012
# Updated    :    21/03/2013
# Authors    : jdalbera – gbs-its-wid-nce
# Comments    : This script query the current DNS to retrieve list of FQDN corresponding
# to list of IPs (reverse records)
# It writes the results to a text file
Write-Host “”
Write-Host “——————————————————-”
Write-Host ” Get DNS records from list of IPs ”
Write-Host “——————————————————-”
Write-Host “”

$date = Get-Date -Format ddMMyyyy
$log = “.\logs\Get-DNSrecordFromIPs-$date.txt”
#$listofIPs = Get-Content .\IPList.txt
$listofIPs = “”,”″,”″
#Lets create a blank array for the resolved names
$ResultList = @()

Write-host “”
Write-host “————————————————————————————————”
Write-host “”
$startscript = Get-Date

# Lets resolve each of these addresses
foreach ($ip in $listofIPs)
$result = $null
$currentEAP = $ErrorActionPreference
$ErrorActionPreference = “silentlycontinue”

#Use the DNS Static .Net class for the reverse lookup
# details on this method found here:
$result = [System.Net.Dns]::gethostentry($ip)
$ErrorActionPreference = $currentEAP
If ($Result) {
$Resultlist += [string]$Result.HostName
Else {
$Resultlist += “$IP – No HostNameFound”
# To output the results to a text file
$resultlist | Out-File $log

Write-host “——————-”
Write-host “– End of Script –”
Write-host “——————-”
Write-host “”
$stopscript = Get-Date
Write-host “Has started at” $startscript -BackgroundColor Gray -ForegroundColor Black
Write-host “Had finished at” $stopscript -BackgroundColor Gray -ForegroundColor Black
Write-host “TIME SPENT:” (New-TimeSpan -Start $startscript -End $stopscript).hours “Hours” (New-TimeSpan -Start $startscript -End $stopscript).minutes “Minutes” (New-TimeSpan -Start $startscript -End $stopscript).seconds “Seconds” -BackgroundColor Green -ForegroundColor Black
Write-host “”
Write-host “”