Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30931 > unrolled thread
| Started by | Johannes Graumann <johannes_graumann@web.de> |
|---|---|
| First post | 2012-10-07 22:44 +0300 |
| Last post | 2012-10-07 23:38 +0300 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
Convert MAC to hex howto Johannes Graumann <johannes_graumann@web.de> - 2012-10-07 22:44 +0300
Re: Convert MAC to hex howto Paul Rubin <no.email@nospam.invalid> - 2012-10-07 12:56 -0700
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 22:44 +0300 |
| Subject | Convert MAC to hex howto |
| Message-ID | <mailman.1931.1349639025.27098.python-list@python.org> |
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.
Sincerely, Joh
[toc] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2012-10-07 12:56 -0700 |
| Message-ID | <7xipamcazs.fsf@ruckus.brouhaha.com> |
| In reply to | #30931 |
Johannes Graumann <johannes_graumann@web.de> 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(':'))
[toc] | [prev] | [next] | [standalone]
| From | Johannes Graumann <johannes_graumann@web.de> |
|---|---|
| Date | 2012-10-07 23:38 +0300 |
| Message-ID | <mailman.1938.1349642407.27098.python-list@python.org> |
| In reply to | #30933 |
Paul Rubin wrote:
> Johannes Graumann <johannes_graumann@web.de> 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(':'))
Thanks to you as well!
Joh
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web