Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Convert MAC to hex howto

Reply
Thread Tools

Re: Convert MAC to hex howto

 
 
Peter Otten
Guest
Posts: n/a
 
      10-07-2012
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, socket.SO_BROADCAST, 1)
> wolsocket.sendto('\xff'*6 + '\x00\x08\x9b\xce\xf5\xd4'*16,
> (expectedlanbroadcast, 80))
>
> This is what I came up whith, but I remain puzzled on how to preserver the
> leading '\h' ... thanks for any hint
>
> expectedservermac = '00:08:9b:ce:f5:d4'
> hexcall = str.split(expectedservermac,":")
> hexcall.insert(0,'')
> hexcall = "\\x".join(hexcall).decode('string_escape')


>>> import binascii
>>> expectedservermac = '00:08:9b:ce:f5:d4'
>>> binascii.unhexlify(expectedservermac.replace(":", ""))

'\x00\x08\x9b\xce\xf5\xd4'


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert MAC to hex howto Johannes Graumann Python 2 10-07-2012 08:38 PM
Re: Convert MAC to hex howto Johannes Graumann Python 0 10-07-2012 08:38 PM
Re: Convert MAC to hex howto MRAB Python 0 10-07-2012 08:04 PM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments