Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fcntl
- import socket
- import struct
- def get_hw_addr(interface):
- with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
- info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', interface[:15].encode()))
- return ':'.join('%02x' % i for i in info[18:24])
- def get_ethernet_addr(interface):
- with socket.socket(socket.AF_PACKET, socket.SOCK_RAW) as s:
- s.bind((interface, 0))
- _, _, _, _, addr = s.getsockname()
- return ':'.join('%02x' % i for i in addr)
- if __name__ == '__main__':
- print(get_hw_addr('enp0s3'))
- print(get_ethernet_addr('enp0s3'))
Add Comment
Please, Sign In to add comment