how to find out mac addresses of all machines on network

Is there some easy way to find out mac address of all machines on my network rather than doing an SSH into each and ifconfig | grep HWaddr if there are 300 machines on network I really need some easy solution.


Solution 1:

You can use nmap to run a ping scan.

nmap -sP 192.168.254.*

Starting Nmap 5.00 ( http://nmap.org ) at 2011-03-09 11:32 GMT
Host xyzzy.lan (192.168.254.189) is up (0.00022s latency).
MAC Address: 00:0C:29:5B:A5:E0 (VMware)
Host plugh.lan (192.168.254.196) is up (0.00014s latency).
MAC Address: 00:0C:29:2E:78:F1 (VMware)
Host foo.lan (192.168.254.200) is up.
Host bar.lan (192.168.254.207) is up (0.00013s latency).
MAC Address: 00:0C:29:2D:94:A0 (VMware)
Nmap done: 256 IP addresses (4 hosts up) scanned in 3.41 seconds

Edit:

A sed script to filter the output to IP -> MAC - put this in a file.

/^Host.*latency.*/{
    $!N
    /MAC Address/{
        s/.*(\(.*\)) .*MAC Address: \(.*\) .*/\1 -> \2/
    }
}  
/[Nn]map/d
s/^Host .*is up/& but MAC Address cannot be found/

and use it like this

nmap -sP 192.168.254.0/20 | sed -f sedscript
192.168.254.189 -> 00:0C:29:5B:A5:E0
192.168.254.196 -> 00:0C:29:2E:78:F1
Host foo.lan (192.168.254.200) is up but MAC Address cannot be found.
192.168.254.207 -> 00:0C:29:2D:94:A0

Solution 2:

Use nmap. Important to run it as root so you get the MAC addresses. Example:

sudo nmap -sP 192.168.1.0/24 

Will scan 192.168.1.1 - 192.168.1.255. Look up CIDR notation on wiki if you're not familiar with this subnet notation.

You should be able to get nmap from the repos of any recentish Linux distro, e.g.

sudo apt-get install nmap

or

sudo yum install nmap

A sample output from my network:

Host 192.168.1.1 is up (0.0069s latency).
MAC Address: 00:0D:54:9B:D8:F4 (3Com)
Host 192.168.1.78 is up (0.0068s latency).
MAC Address: 00:0C:29:BC:3D:1C (VMware)
Host 192.168.1.91 is up (0.0038s latency).
MAC Address: 00:0C:29:8A:F4:A3 (VMware)
Host 192.168.1.92 is up (0.0039s latency).
MAC Address: 00:0C:29:65:60:5F (VMware)
Host 192.168.1.158 is up (0.033s latency).
MAC Address: 00:0C:29:82:24:EA (VMware)
Host 192.168.1.186 is up (0.0024s latency).
MAC Address: 00:0C:29:3E:26:1F (VMware)
Host 192.168.1.190 is up (0.0066s latency).

Solution 3:

Try this command:

arp-scan --interface=eth0 192.168.1.0/24