You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
591 B

import platform
import socket
import struct
def get_mac_address(interface='eth0') -> str:
os_name = platform.system()
if os_name=="Windows":
return "mac_win_123"
else:
import fcntl
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mac = fcntl.ioctl(
sock.fileno(),
0x8927,
struct.pack('256s', interface[:15].encode('utf-8'))
)
mac_address = ':'.join(['%02x' % b for b in mac[18:24]])
return mac_address
if __name__ == '__main__':
mac_str=get_mac_address()
print(mac_str)