get all mac address from network

get all mac address and ip from your network gateway order by ip

nmap -sP $( ip route | grep '^default' | egrep -o '([0-9]{1,3}\.){3}' )0/24; arp -a | sort -n -t . -k 4 | awk '{print "mac:", $4, "#"$2}'

get all ip and mac address from your network gateway

nmap -sn -PO $( ip route | grep default | egrep -o '([0-9]{1,3}\.){3}' )0/24 | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}|[[:xdigit:]:]{6,}' | awk 'BEGIN{ m=0 } { if ( $1 ~ /^[[:digit:].]{3,}/ ) m++; print m, $0 }' | awk '{ a[$1] = a[$1] FS substr( $0, index( $0,$2 ) ) } END{ for( i in a ) print i a[i] }'

get all ip and mac address from a network range with ssh open

nmap -sS -p 22 --open $( ip route | grep default | egrep -o '([0-9]{1,3}\.){3}' )0/24 | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}|[[:xdigit:]:]{6,}' | awk 'BEGIN{ m=0 } { if ( $1 ~ /^[[:digit:].]{3,}/ ) m++; print m, $0 }' | awk '{ a[$1] = a[$1] FS substr( $0, index( $0,$2 ) ) } END{ for( i in a ) print i a[i] }'

A full script sample to get all IPs and MACs of an entire network:
https://github.com/nickollasc/get_all_ips_and_macs_of_network