Re: Convert MAC to hex howto

2012-10-07 Thread Peter Otten
Johannes Graumann wrote: > Dear all, > > I'm trying to convert > '00:08:9b:ce:f5:d4' > to > '\x00\x08\x9b\xce\xf5\xd4' > for use in magic packet construction for WakeOnLan like so: > wolsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >wolsocket.setsockopt(socket.SOL_SOCKET, sock

Re: Convert MAC to hex howto

2012-10-07 Thread Johannes Graumann
Paul Rubin wrote: > Johannes Graumann writes: >> '00:08:9b:ce:f5:d4' >> ... >> hexcall = "\\x".join(hexcall).decode('string_escape') > > I think it's best not to mess with stuff like that. Convert to integers > then convert back: > > mac = '00:08:9b:ce:f5:d4' > hexcall = ''.join(chr(int(c,

Re: Convert MAC to hex howto

2012-10-07 Thread Johannes Graumann
MRAB wrote: > On 2012-10-07 20:44, Johannes Graumann wrote: >> Dear all, >> >> I'm trying to convert >> '00:08:9b:ce:f5:d4' >> to >> '\x00\x08\x9b\xce\xf5\xd4' >> for use in magic packet construction for WakeOnLan like so: >> wolsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >>

Re: Convert MAC to hex howto

2012-10-07 Thread MRAB
On 2012-10-07 20:44, Johannes Graumann wrote: Dear all, I'm trying to convert '00:08:9b:ce:f5:d4' to '\x00\x08\x9b\xce\xf5\xd4' for use in magic packet construction for WakeOnLan like so: wolsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) wolsock

Re: Convert MAC to hex howto

2012-10-07 Thread Paul Rubin
Johannes Graumann writes: > '00:08:9b:ce:f5:d4' > ... > hexcall = "\\x".join(hexcall).decode('string_escape') I think it's best not to mess with stuff like that. Convert to integers then convert back: mac = '00:08:9b:ce:f5:d4' hexcall = ''.join(chr(int(c,16)) for c in mac.split(':'))