简体   繁体   中英

Get only Mac address from IP (bash)

I want to grep the MAC address in arp -n .

I tried this: $ arp | grep 192.168.15.1 | awk '{print $3}' $ arp | grep 192.168.15.1 | awk '{print $3}'

But i end up like this:

00:00:00:00:00:00
00:00:00:00:00:00
00:00:00:00:00:00
00:00:00:00:00:00
00:00:00:00:00:00
00:00:00:00:00:00

I censored the macs

I want only a single MAC address, how can i get it ?

arp | awk '/192.168.15.1/{print $3;exit}'

By using this command, you will get only 1 mac.

If you want to adopt an input of bash script to be the addr, use the command below,

arp -n $1 | awk -v a=$1 '$0 ~ a{print $3;exit}'

use -va=$1 to assign $1 of bash to the variable a in awk

ip -brief link show |grep -v LOOPBACK|awk '{print $3;}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM