Code I'm attempting to use in python 3.4:
#!/usr/bin/python3
def get_mac_addr(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]
print (get_mac_addr('eth0'))
Error: struct.error: argument for 's' must be a bytes object
I see that this code does work when not using python3 but I need it in 3 for my project. I tried comparing to problem: Struct.Error, Must Be a Bytes Object? but I couldn't see how I can apply this to myself.