Skip to content

Instantly share code, notes, and snippets.

View JayZar21's full-sized avatar
💭
I may be slow to respond.

Gianluca Romanin JayZar21

💭
I may be slow to respond.
View GitHub Profile
@JayZar21
JayZar21 / get_mac_address.py
Last active April 20, 2020 13:39 — forked from zhenyi2697/get_mac_address.py
Python: get mac address of a interface
# Python 2:
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]