48

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

Graviton
  • 2,775
  • 12
  • 41
  • 62
  • Can't be done in general. Certain OSes and networking systems can go some way to doing this, so if you edit your question to include that information, you might get more directed answers. – womble Jun 24 '09 at 03:12
  • The network name is a Windows construct, and has nothing to do with TCP/IP. – Dave Cheney Jun 24 '09 at 03:21
  • @David Cheney: What if the OP meant hostname and they're not Windows systems? I don't see anything to indicate either way. I think it's up to the OP to disambiguate in this instance. – Dennis Williamson Jun 24 '09 at 03:58
  • Related: [How to get a list of all IP addresses (and ideally device names) on a LAN?](https://serverfault.com/q/10590/407822) – Stevoisiak Jun 21 '18 at 15:56

7 Answers7

42
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.

Kiwi
  • 103
  • 3
sysadmin1138
  • 131,083
  • 18
  • 173
  • 296
  • 3
    I don't have nmap in my windows – Jonny Apr 18 '13 at 11:51
  • 2
    Jonny, are you an admin or a user? If you are not an admin, what is the reason you need/want to do this scan? If you are an admin, nmap is a very handy tool to have around. – music2myear Oct 10 '13 at 14:21
  • 1
    I found that nslookup did not work for me, it wasn't scanning my local network (scanning something of comcast's maybe?). I changed `@nslookup` to `@ping`. While obviously much slower, it automated doing this process by hand... – Snappawapa Aug 05 '17 at 18:32
  • Replace `-sP` with `-sn` if using the latest version of nmap: "In previous releases of Nmap, -sn was known as -sP." ([source](https://nmap.org/book/man-host-discovery.html)) – Kiwi May 09 '20 at 14:44
7

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"

CMD nerd...
  • 91
  • 1
  • 1
5

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
Jordan W.
  • 1,403
  • 1
  • 13
  • 19
4

If you want to go for "regular", nmap will do just fine.

If you want to go for "obscure", Doxpara Paketto Keiretsu will do that with scanrand and friends. Not exactly "offical" tools but certainly useful for finding nodes you can't otherwise see. And did I mention it's fast?

Avery Payne
  • 14,326
  • 1
  • 48
  • 87
4

If you don't mind installing this small app: Radmin's Advanced IP Scanner (Freeware for Windows)

Provides you with Local Network hosts:

  • IP
  • NetBIOS name
  • Ping time
  • MAC address
  • Remote shutdown (windows only, I pressume), and others

Advanced IP Scanner is a fast, robust and easy-to-use IP scanner for Windows. It easily lets you have various types of information about local network computers in a few seconds! Advanced IP Scanner gives you one-click access to many useful functions - remote shutdown and wake up, Radmin integration and more! Powered with multithread scan technology, this program can scan hundreds computers per second, allowing you to scan 'C' or even 'B' class network even from your modem connection.

l0c0b0x
  • 11,697
  • 6
  • 46
  • 76
2

There is a tool i like to use especially when i'd like to find a free IP in the chaos i like to call my network. It is called IP-Tools by KS-Soft and does @sysadmin1138s suggestion graphically. It has 18 other great utilities as well. It is a great little swiss army knife

Stevoisiak
  • 123
  • 8
jake
  • 194
  • 1
  • 4
  • 12
-2

May help:

If you do have a server name and want to look up the IP for it (vice versa too), use cmd => nslookup "put your server name here"

Yarik
  • 11