Skip to content

Instantly share code, notes, and snippets.

@zhenyi2697
Created July 25, 2013 14:45
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save zhenyi2697/6080400 to your computer and use it in GitHub Desktop.
Save zhenyi2697/6080400 to your computer and use it in GitHub Desktop.
Python: get mac address of a interface
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]
@ashishoist91
Copy link

IS it really work

@roramirez
Copy link

Good!

@danilodene
Copy link

Works great ! =D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment