How to get the MAC address of the 'local' system given the IP address?

MR ZenWiz mrzenwiz at gmail.com
Thu Jan 30 17:54:44 UTC 2020


On Thu, Jan 30, 2020 at 9:24 AM Chris Green <cl at isbd.net> wrote:
>
:
> ... but I can't find a neat way of getting the corresponding MAC
> address and company information as for arp-scan. The MAC address can
> be obtained using ifconfig or ip but it's an exercise in frustration
> trying to extract the relevant bits:-
>
Construct an awk script that takes the output of ifconfig (or ip a)
and produces the desired MAC address (ether for ifconfig, link/ether
for ip) if there is one.

You can have it run on all interfaces or just the one you're
interested in.  You can even make it smart enough to find the IP
address and output just that MAC address.

If you don't know how to use awk, it may take a few tries and a lot of
man page references, but an exercise in frustration?  Sounds to me
like not enough effort applied.  Besides, once you learn to do this,
more awk scripts become much easier.

You can also do it in a shell script, but that is a little trickier
and involves more command breadth - awk is simpler.

Mark




More information about the ubuntu-users mailing list