I'm working on a program that depends on scanning the local network for all connected devices and getting their MAC address.
To do this, I'm running the following command:
nmap -sn 10.0.0.*
This is working for the most part. The issue I'm having is that sometimes the result correctly outputs information about all of the devices on the network, but other times it only outputs information about my router.
I know that sometimes devices might drop off the network temporarily, but it seems like at a minimum it should return two results (one for the computer I'm running the command from and one from the router).
Is there any explanation for this behavior, or circumstances that might cause it? Alternately, is there a better way to achieve the same result with more consistency?
In case it's relevant, I'm running nmap 6.47, installed with brew on a MacBook connected wirelessly to the router.
UPDATE
After making the sample I realized that I actually am never getting fewer than two results. It's just that the address for the computer I'm running the command from (10.0.0.54) doesn't return a MAC address. Sorry for the misinformation, I was running the output through grep to extract the MAC addresses. However, when I was making the sample there were certainly more than two devices on the network - at least one of my other computers was connected.
Sample:
Normal result:
$ nmap -sn 10.0.0.*
Starting Nmap 6.47 ( http://nmap.org ) at 2015-07-03 18:53 CDT
Nmap scan report for 10.0.0.1
Host is up (0.0043s latency).
MAC Address: B8:9B:C9:98:40:92 (SMC Networks)
Nmap scan report for 10.0.0.50
Host is up (0.023s latency).
MAC Address: B0:05:94:04:CA:75 (Liteon Technology)
Nmap scan report for 10.0.0.51
Host is up (0.080s latency).
MAC Address: F8:27:93:B4:09:F9 (Apple)
Nmap scan report for 10.0.0.57
Host is up (0.093s latency).
MAC Address: 78:4B:87:47:EA:50 (Murata Manufacturing Co.)
Nmap scan report for 10.0.0.58
Host is up (0.070s latency).
MAC Address: A4:5E:60:B8:D5:A7 (Unknown)
Nmap scan report for 10.0.0.59
Host is up (0.094s latency).
MAC Address: 70:3E:AC:1C:DB:D8 (Unknown)
Nmap scan report for 10.0.0.54
Host is up.
Nmap done: 256 IP addresses (7 hosts up) scanned in 26.23 seconds
Not as many devices as expected:
$ nmap -sn 10.0.0.*
Starting Nmap 6.47 ( http://nmap.org ) at 2015-07-03 18:55 CDT
Nmap scan report for 10.0.0.1
Host is up (0.0044s latency).
MAC Address: B8:9B:C9:98:40:92 (SMC Networks)
Nmap scan report for 10.0.0.54
Host is up.
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.04 seconds
$ nmap -sn 10.0.0.*
Starting Nmap 6.47 ( http://nmap.org ) at 2015-07-03 18:55 CDT
Nmap scan report for 10.0.0.1
Host is up (0.0034s latency).
MAC Address: B8:9B:C9:98:40:92 (SMC Networks)
Nmap scan report for 10.0.0.54
Host is up.
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.03 seconds
$ nmap -sn 10.0.0.*
Starting Nmap 6.47 ( http://nmap.org ) at 2015-07-03 18:55 CDT
Nmap scan report for 10.0.0.1
Host is up (0.0037s latency).
MAC Address: B8:9B:C9:98:40:92 (SMC Networks)
Nmap scan report for 10.0.0.54
Host is up.
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.06 seconds
Normal result again:
$ nmap -sn 10.0.0.*
Starting Nmap 6.47 ( http://nmap.org ) at 2015-07-03 18:55 CDT
Nmap scan report for 10.0.0.1
Host is up (0.025s latency).
MAC Address: B8:9B:C9:98:40:92 (SMC Networks)
Nmap scan report for 10.0.0.50
Host is up (0.054s latency).
MAC Address: B0:05:94:04:CA:75 (Liteon Technology)
Nmap scan report for 10.0.0.57
Host is up (0.054s latency).
MAC Address: 78:4B:87:47:EA:50 (Murata Manufacturing Co.)
Nmap scan report for 10.0.0.54
Host is up.
Nmap done: 256 IP addresses (4 hosts up) scanned in 7.79 seconds