Robert Moore
Robert Moore

Reputation: 2582

List ALL devices on local network?

I want to generate a list of all devices on a local network. I have tried the command arp -a and it has listed some devices, but not all of them.

The ifconfig command shows my IP address and MAC address along with some other useful information, but it doesn't show all of the devices on the local network.

Is there a command that shows all IP addresses?

Upvotes: 10

Views: 74613

Answers (2)

Richard Chambers
Richard Chambers

Reputation: 17623

There are several ways to generate list of devices on a network however it depends on what resources you have available to use.

  • ping the possible list of devices
  • access the list of devices from your router
  • use a third party wire sniffing tool

Note that there are a number of reasons why a device may be on a network yet not "discoverable". For a Windows PC, Network discovery may be turned off. A firewall may be filtering out ICMP Echo requests or replying to ICMP Echo requests may be turned off.

Ping the network for devices - Windows OS

To generate a list with a Windows CMD .bat file to ping devices on the network, do the following.

Create a .bat file with a loop that uses the ping command to send a ping to each of the possible usable addresses on your network. I use the -a and -n 1 options on the ping command to send a single ping, -n 1, with a request to give me the hostname. After pinging the network you can then use the arp command to get a concise list using arp -a >con which will redirect the output to the console even when the .bat file is redirected to a file.

The following commands in a Windows .bat file seems to do the trick.

for /L %%i in (1,1,254) do (
ping -a -n 1 192.168.0.%%i 
)

arp -a >con

Next run the .bat file sending the output to a text file:

listdev.bat > listdev.txt

This will generate a text file with the results of the ping commands. It will look something like the following:

C:\Users\rcham>(ping -a -n 1 192.168.0.3  ) 

Pinging DESKTOP-GFSP7AC.xxxxxxxx.net [192.168.0.3] with 32 bytes of data:
Request timed out.

Ping statistics for 192.168.0.3:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

C:\Users\rcham>(ping -a -n 1 192.168.0.4  ) 

Pinging rick-MS-7B98.xxxxxxxx.net [192.168.0.4] with 32 bytes of data:
Reply from 192.168.0.4: bytes=32 time=5ms TTL=64

Ping statistics for 192.168.0.4:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 5ms, Maximum = 5ms, Average = 5ms

C:\Users\rcham>(ping -a -n 1 192.168.0.5  ) 

Pinging 192.168.0.5 with 32 bytes of data:
Reply from 192.168.0.148: Destination host unreachable.

Ping statistics for 192.168.0.5:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

C:\Users\rcham>(ping -a -n 1 192.168.0.6  ) 

Pinging 192.168.0.6 with 32 bytes of data:
Reply from 192.168.0.148: Destination host unreachable.

Ping statistics for 192.168.0.6:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

C:\Users\rcham>(ping -a -n 1 192.168.0.7  ) 

Pinging 192.168.0.7 with 32 bytes of data:
Reply from 192.168.0.148: Destination host unreachable.

Ping statistics for 192.168.0.7:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

C:\Users\rcham>(ping -a -n 1 192.168.0.8  ) 

Pinging SurfacePro-2.xxxxxxxx.net [192.168.0.8] with 32 bytes of data:
Reply from 192.168.0.148: Destination host unreachable.

Ping statistics for 192.168.0.8:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

C:\Users\rcham>(ping -a -n 1 192.168.0.9  ) 

Pinging starfive.xxxxxxxx.net [192.168.0.9] with 32 bytes of data:
Reply from 192.168.0.148: Destination host unreachable.

Ping statistics for 192.168.0.9:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

Notice in the list above that there are differences in responses to the ping command.

  • response received
  • request timed out
  • reply of Destination host unreachable.

The first means that there was an operational device connected to the network with that IP address and the device was configured to reply to the ICMP Echo request of the ping command.

The second means that there may be a device connected to the network with that IP address however the device may be configured to ignore ICMP Echo requests or it is powered off and can't reply. There may be other possible causes but these two are the most common in a small network.

The third means the router didn't have a way to send the ICMP Echo request to the designated IP address so the request wasn't sent.

For the difference between the two last responses with more details see the post ping response "Request timed out." vs "Destination Host unreachable"

Upvotes: 1

Krzysztof Sawicki
Krzysztof Sawicki

Reputation: 414

arp -a will show you only MAC addresses that are stored in local ARP cache and your computer was connected to. When I'm trying to see every device in my local network I have to scan it. For example if you have 192.168.1.0/24 network you can do:

$ for i in `seq 1 254`; do
ping -c 1 -q 192.168.1.$i &
done

You will try to ping every computer in your network. Of course not every computer will answer for ping. This is why you can't rely on ping. Now you need to check ARP cache.

$ arp -a | grep 192.168.1. | grep ether

This command will show you ARP cache filtered only with computers that are in this network and that answered on ARP requests (in 99% cases it will be full list of devices in your network - just remember that ARP entry is not removed immediately when the device disconnects).

Upvotes: 23

Related Questions