ftao / python-ifcfg

Python cross-platform network interface discovery (ifconfig/ipconfig/ip)
BSD 3-Clause "New" or "Revised" License
55 stars 37 forks source link

Add 'lladr' to ifconfig command #52

Closed dataspot2002 closed 4 years ago

dataspot2002 commented 4 years ago

Hi, I am new to GitHub and just started to use ifcfg. In my code I have used ifcfg.distro = 'Linux' to parse saved output of ifconfig. but it is not picking up values of lladdr, which holds the interface mac address. It would be nice to have this included in the next version.

In the meantime, can you suggest a way to implement this for my current project as I need to extract the MAC address.

Below is an example snippet of the ifconfig output. Highlighted in bold is the value I am looking to extract.

Please let me know if you like any more information.

ifconfig

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33200 priority: 0 groups: lo inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5 em0: flags=8b43<UP,BROADCAST,RUNNING,PROMISC,ALLMULTI,SIMPLEX,MULTICAST> mtu 1500 lladdr 00:00:00:00:00:a8 priority: 0 media: Ethernet 100baseTX (1000baseT full-duplex,) status: active inet6 ffff::fff:ffff:ffff:ff%em0 prefixlen 64 scopeid 0x1

ftao commented 4 years ago

Base on your sample output, you can try adding following line after line 280.

https://github.com/ftao/python-ifcfg/blob/8928504d41e89039ff08c06feb151cd955f943cd/src/ifcfg/parser.py#L280

            r'.*(lladdr\s*)(?P<lladdr>[^\s\/]+)',
dataspot2002 commented 4 years ago

Just tried it and it's just what I needed.

Thanks for the quick reply.