Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Using Ubuntu 10.10, I was wondering if there was a command line command that can list all the IPs of devices connected to the network?

I would use this for example, to list all the computers connected to my home network. Ideally, it needs to be command line as I will be running it from C++.

Any ideas?

share|improve this question

5 Answers 5

up vote 64 down vote accepted

Check out the arp-scan command - you will probably have to install it eg:

sudo apt-get install arp-scan

http://manpages.ubuntu.com/manpages/hardy/man1/arp-scan.1.html

And to give further detail:

sudo arp-scan --interface=eth0 --localnet

Where eth0 is your device. You can find your device with:

ifconfig
share|improve this answer
    
Perfect, thank you. Returns exactly the format I need. –  Christopher Gwilliams Mar 24 '11 at 14:09
    
Works perfectly on OSX too! Installed with Brew, and interface was en0, rather than eth0, but works great. –  nthonygreen Apr 13 '13 at 16:00
2  
If your connected to your network using wifi use wlan0 instead of eth0. –  Neil Sep 15 '13 at 12:04
    
Can you get this to list hostnames as well as IP addresses? –  user1527227 Feb 4 at 18:57
    
It's worth noting that this does not use the ARP cache: it performs an actual scan. Unlike most nmap scans, this cannot cross layer 3 boundaries, which is usually what you want in this scenario. (In other words, it's limited to your subnet.) –  Zenexer Sep 29 at 12:26

Use nmap. example: nmap -sn 10.10.10.0/24 The arp cache will only tell you those that you have tried to contact recently.

share|improve this answer

In windows this would be "arp -a" I believe that an equivalent of that in Linux would be "arp -e".

This information can be found from the man page for arp :

arp with no mode specifier will print the current content of the table.
-e : Use default Linux style output format (with fixed columns).
share|improve this answer
    
That looks like it works (may need to have a play as I am on a public network so it only seems to list all the servers on the network. –  Christopher Gwilliams Mar 24 '11 at 13:37
    
If I am on a home network, will it just list the devices connected to my router? Thanks! –  Christopher Gwilliams Mar 24 '11 at 13:37
    
That command will only list the devices in the hosts current arp cache and that will only be the ones which the host has contacted recently. –  Linker3000 Mar 24 '11 at 13:38

Try installing nmap (sudo apt-get install nmap) and type nmap 192.168.1.0/24 substituting 192.168.1 with the first three parts of your ip address (find out using ip addr).

share|improve this answer

If your network is 192.168.0.0/24, make an executable file with the following code; Change the 192.168.0 to your actual network.

#!/bin/bash
for ip in 192.168.0.{1..254}; do
  ping -c 1 -W 1 $ip | grep "64 bytes" &
done
share|improve this answer
    
Hi Anders... The user's network might not be 192.168.0.0/24; I made a note. The site's formatting did not like a bare #!, and so clobbered the formatting of the code snippet: when entering code, use the blockquote or preformatted text buttons, and review your answer for proper formatting before submitting it, as carriage returns, tabs, and spaces might have been stripped. –  Nevin Williams May 17 '13 at 19:34
    
As well, when supplying a script that needs to be put into a file and made executable, rather than simply cut & pasted, it's probably best that you specify this; it may not be obvious to some what all is required to implement your solution. –  Nevin Williams May 17 '13 at 19:37
4  
Technically, this will only return hosts that respond to ping. There may be hosts that are connected, but not replying to ICMP echo requests. As well, one can broadcast one packet to an entire network by specifying the broadcast address, which is the last address in the IP network: ping -c 1 -W 1 192.168.0.255 would accomplish the same as the for loop. –  Nevin Williams May 17 '13 at 19:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.