Saturday, September 15, 2012

Get specific PC IP from "arp -a"

I want to extract IP of machine leonidas. arp -a returns such line (among others): 
leonidas.home (192.168.1.5) at 0:1c:c0:de:8f:28 on en1 ifscope [ethernet] 

To have only IP:
arp -a | grep leonidas | cut -f 2 -d ' ' | sed 's/[()]//g'
prints
192.168.1.5

4 comments:

Koziołek said...

easier way:
arp | grep wlan0 | awk '{print $1}'

use host name rather than interface name

Anonymous said...
This comment has been removed by a blog administrator.
Finn said...
This comment has been removed by a blog administrator.
Unknown said...
This comment has been removed by a blog administrator.