Is there a way to get a hostname from an IP address without depending on a DNS inquiry?

Viewed 59410

I'm trying to write a script that depends on knowing the names of the computers on a network segment, but all the scripts I've found depend on a DNS inquiry which only replys with the names of a few of the machines. For example:

[System.Net.Dns]::GetHostbyAddress($IPAddress) 

I've also tried using

Ping -a $ipaddress

but this often fails to return the machine name as well. Is there a way to ask the host what it's name is directly and what level of permissions might be required in AD to get a response?
Thanks in advance.

6 Answers

COMMAND:

wmic.exe /node:10.20.30.40 OS get CSName /format:list 

BATCH FILE FOR WHOLE SUBNET:

for /L %%z in (1,1,254) do wmic.exe /node:10.20.30.%%z OS get CSName /format:list 2>NUL

Another idea might be to query your SCCM server if you have one:

(Get-WmiObject -Query "SELECT * from SMS_R_SYSTEM WHERE IPAddresses LIKE '%$ipaddress%'" -Namespace "root\sms\site_$SiteCode" -computerName $SCCMServer).Name

Another idea using powershell:

Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computer -Property Name | ForEach-Object {$_.Name}

Where $Computer is an IP address

Related