Get IP addresses and computer names in the same network

What is the command that can be used to get the IP address and the names of the computers that are located in the same network?

I am running Windows


Solution 1:

nmap -sn 192.168.1.0/24 

Put your network number in it. It'll do a ping-sweep of your network and report the reverse DNS's of the up machines. Won't find down machines.

C:> for /L %N in (1,1,254) do @nslookup 192.168.0.%N >> names.txt

That'll do a reverse lookup of every IP in your subnet.

Solution 2:

Try using this simple command prompt code. To get all the network ips arp -a to find where an ip is coming from tracert "ip"

Solution 3:

Using Powershell - dmitrysotnikov wrote a nice function, this is from: http://dmitrysotnikov.wordpress.com/2008/03/07/get-computer-by-ip-address/

does need some error handling for cleaner 'time-out' and 'host not found' replies.

function Get-ComputerNameByIP {
param(
$IPAddress = $null
)
BEGIN {
}
PROCESS {
if ($IPAddress -and $_) {
throw ‘Please use either pipeline or input parameter’
break
} elseif ($IPAddress) {
([System.Net.Dns]::GetHostbyAddress($IPAddress))
} elseif ($_) {
trap [Exception] {
write-warning $_.Exception.Message
continue;
}
[System.Net.Dns]::GetHostbyAddress($_)
} else {
$IPAddress = Read-Host “Please supply the IP Address”
[System.Net.Dns]::GetHostbyAddress($IPAddress)
}
}
END {
}
}

#Use any range you want here
1..255 | ForEach-Object {”10.20.100.$_”} | Get-ComputerNameByIP