Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python get mac add cross platform

get the MAC address on both Windows and othe oss.

Please provide a more best approach to get the MAC address, it functions should work on both Windows and others oss.

need a solution and a approach for code for this ; need best method to do

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

install
pip install netifaces

import netifaces as ni

def get_mac_address():

    interfaces = ni.interfaces()


    for interface in interfaces:
        try:

            address_info = ni.ifaddresses(interface)[ni.AF_LINK]
            mac_address = address_info[0]['addr']
            return mac_address
        except ValueError:

            continue


    return None


mac_address = get_mac_address()


if mac_address:
    print("MAC Address:", mac_address)
else:
    print("MAC Address not found.")

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading