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

Oliver Grawert ogra at ubuntu.com
Fri Jan 31 07:09:04 UTC 2020


hi,
Am Donnerstag, den 30.01.2020, 20:12 +0000 schrieb Chris Green:
> On Thu, Jan 30, 2020 at 05:25:33PM +0000, Paul Sladen wrote:
> > 
> > On Thu, 30 Jan 2020, Chris Green wrote:
> > > 
> > > ... find a neat way of getting the corresponding MAC
> > $ grep . /sys/class/net/*/address
> > 
> > Then look up the vendor prefixes in a copy of 'oui.txt'.
> > 
> But that gives me:-
> 
>     /sys/class/net/enp0s25/address:90:1b:0e:06:bc:91
>     /sys/class/net/lo/address:00:00:00:00:00:00
> 
> and I don't know which device corresponds to my LAN IP address.  More
> significantly if my wired connection is up too there will be three
> lines returned. 

go by the default route then:

grep . /sys/class/net/$(route -n|grep ^0.0.0.0|sed 's/^.* //')/address

ciao
	oli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20200131/4b23b4d6/attachment.sig>


More information about the ubuntu-users mailing list