[Tutor] packet parsing
dman
dsh8290@rit.edu
Thu, 28 Feb 2002 17:43:26 -0500
On Thu, Feb 28, 2002 at 10:34:49PM +0100, Remco Gerlich wrote:
| On 0, python@jayed.com wrote:
| > OK, that makes sense. But how do I peel of individual bytes? (I just
| > played with lstrip and am not having any luck -- but this is probably my
| > lack of knowledge).
|
| kexrecv[0] is the first byte, kexrecv[1] the second, etc.
|
| Try
|
| for byte ik kexrecv:
| print ord(byte)
|
| To see the integer values.
In addition, look at the 'struct' module. It contains methods to
treat strings as packed binary data. For example,
# turn my PyInt object into a bitstream :
s = struct.pack( "> i " , 13 )
# turn the bitsequence into a PyInt so I can perform mathmatical
# operations on it :
i = struct.unpack( "> i " , "\x00\x00\x00\x0d" )[ 0 ]
(note that in this example, s will have the value that is passed to
unpack() as a literal)
Try it out! :-). And read the docs too.
-D
--
If we claim we have not sinned, we make Him out to be a liar and His
Word has no place in our lives.
I John 1:10