-3

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

kevin g
  • 3
  • 1

1 Answers1

0

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.")

geroge
  • 52
  • 6