How would I find out all the devices on my LAN by pinging them all in terminal? What would the code be?
Probably the easiest way to do this is to use a command line utility called nmap. You can download the binaries from the main site. Alternatively, if you have Homebrew installed, you can use that to install nmap from a terminal by typing
Once you have downloaded and installed nmap, you need one other piece of information about your LAN - what block of IP address are used for machines on it. The easiest way to find that out is to run
On my network, my machine has the address 192.168.0.6 on interface en1.
NOTE: depending on how many machines you have on your network, pinging them all could take a very very long time. In the following examples, I'll assume you have less than 256 devices on your network and that they are all in the same subnet - likely to be the case if this is a home network.
If your inet looks like 192.168.N.N (where each N is a number between 0-255) then the following command will try to ping addresses 192.168.N.0 to 192.168.N.255 on your network, and report any machines which respond (you need to use sudo so that nmap can use ICMP pings). Fill in the N sections with the matching number in your inet address:
For example, if your inet address was reported as 192.168.1.100, you should type:
If your inet address looks like 10.N.N.N, use this, again filling in the N sections with your own reported numbers:
And finally, if it looks like 172.N.N.N, use this:
Searching Larger Networks
If you want to expand your search to include more machines, you have to adjust the number after the slash in the address section for the command. In the three commands above, I've specified
Every time you decrease the number by 1, twice as many addresses are searched - this is why decreasing it too much can make the search take a very very long time. For example, to search all 192.168.N.N addresses, you would specify
I don't actually know how many pings per second nmap can send, but if you try a full scan, you may have to leave it overnight, or at least have a long coffee.
Those nmap Options
Just so you know, here's what the other nmap options I specified mean:
As the "no port scan" option may hint at, you can do all sorts of very funky things with nmap, such as checking to see what ports are open on a machine (to tell what services they are probably running) and it can even guess which OS the target machine is running with a pretty decent degree of accuracy. If you need more advanced things like that, check the nmap docs. I'd link to them, but I'm not renowned enough to post more than 2 links yet.
Or ping the broadcast address
If everything is turned on, responsive and in one subnet then something like 'ping 192.168.1' for a few seconds followed by 'arp -a' should give you a list of all the devices with ip address and MAC address.