Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30938 > unrolled thread
| Started by | Johannes Graumann <johannes_graumann@web.de> |
|---|---|
| First post | 2012-10-07 23:38 +0300 |
| Last post | 2012-10-07 23:38 +0300 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Convert MAC to hex howto Johannes Graumann <johannes_graumann@web.de> - 2012-10-07 23:38 +0300
| From | Johannes Graumann <johannes_graumann@web.de> |
|---|---|
| Date | 2012-10-07 23:38 +0300 |
| Subject | Re: Convert MAC to hex howto |
| Message-ID | <mailman.1937.1349642250.27098.python-list@python.org> |
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)
>> 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')
>>
>> Thanks for any pointers.
>>
> It looks like you're using Python 2, so:
>
> >>> s = '00:08:9b:ce:f5:d4'
> >>> "".join(chr(int(x, 16)) for x in s.split(":"))
> '\x00\x08\x9b\xce\xf5\xd4'
Many thanks!
Joh
Back to top | Article view | comp.lang.python
csiph-web