-
-
Save roramirez/64cb46199c1e623dfd3f to your computer and use it in GitHub Desktop.
Python: get mac address of a interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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