Question: Hi I'm working on a small bash script that will scan lan every 5 minutes and get live host and then get theirs MAC addresses.

So far I have this:

```
nmap -sP -n -oG - 10.0.0.1-20 | grep "Up" | awk '{print $2}'

```

Which gives me ip addresses. Now I have to do something like

```
arp -an | grep 'ip'

```

but I'm new to bash and I don't know how :)

Answer: 
Here is a script that does exactly what you want:

```
#!/bin/bash

HOSTS=$(nmap -sP -n -oG - 192.168.1.1-10 | grep "Up" | awk '{print $2}')

for host in ${HOSTS}; do
  arp -an | grep ${host} | awk '{print $2 $4}'
done

```
This one outputs all records in a greppable format: 

```
nmap -n -sP 10.0.3.0/24 | awk '/Nmap scan report/{printf $5;printf " ";getline;getline;print $3;}'

```

It seems to work also for IP's/MAC's which are not already in the hosts ARP table. That's a good thing. On my system the script from the accepted answer only shows hosts which are listed in the ARP table...

Results in:

```
10.0.3.100 B8:27:EB:8E:C5:51
10.0.3.101 00:26:B6:E1:4B:EB
10.0.3.112 00:01:29:02:55:25
etc..

```