Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30931

Convert MAC to hex howto

From Johannes Graumann <johannes_graumann@web.de>
Subject Convert MAC to hex howto
Followup-To gmane.comp.python.general
Date 2012-10-07 22:44 +0300
Newsgroups comp.lang.python
Message-ID <mailman.1931.1349639025.27098.python-list@python.org> (permalink)

Followups directed to: gmane.comp.python.general

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

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

csiph-web