Warm tip: This article is reproduced from serverfault.com, please click

nmap command to list the Mac OS x machines in network

发布于 2021-01-07 13:02:21

I know the Nmap command using terminal to list all the live hosts in my WiFi network. How to tell Namp to list only mac ox IP address only.

This is possible using Nmap?. I guess it should be possible. Since Finder -> Network is able to show the hostnames of other machines on the network.

nmap -sP 192.168.0.0/24
Questioner
Kharthigeyan
Viewed
0
Raman Sailopal 2021-01-11 22:21:52

You can use the -A flag of nmap and then pipe through to awk to print only the IP addresses you need. I have no Mac machines on my network but taking Windows machines as an alternate example:

nmap -A 192.168.0.0/24 | awk '/^Nmap scan report for/ { ip=$5 } /^Service Info:/ { split($0,map,":");if ( map[3] ~ "Mac OS X" ) { print ip } }'

Take the output of nmap and then, for each line starting with "Nmap scan report for", store the 5th space delimited field in the variable ip. Then when a line starts with "Service Info:", split the line into an array map based on ":" as the delimiter. Print the variable ip if the 3rd index of the map field pattern matches "Windows" (Change this to what ever text shows for Mac machines)