Skip to content

Instantly share code, notes, and snippets.

@Ismael-VC
Forked from zhenyi2697/get_mac_address.py
Last active August 29, 2015 14:13
Show Gist options
  • Save Ismael-VC/72dbb4b1dc08a311740c to your computer and use it in GitHub Desktop.
Save Ismael-VC/72dbb4b1dc08a311740c to your computer and use it in GitHub Desktop.
import socket
import fcntl
import struct
def getHwAddr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment