design help/questions

Amritansh Raghav amritansh at mobilian.com
Wed Jan 17 14:59:55 EST 2001


Hi
Disclaimer: I'm a Python newbie (been less than 2 days since I first looked
at it) and I am searching the web for answers to these questions too, but
since I am under a tight schedule, I was hoping someone could help me with
these questions:

So here is what I need to do. I'm trying to write a scripting tool for our
test team. They wish to send arbitrary packets over the network.  What I'd
like to do is allow the testers to specify any packet in a text file - say
something like this:
<IP>
    "VersionLength"          0        1    # Name of field, Starting offset,
Length in bytes
    "TOS"                        1        1
    "Length"                     2        2
    "Id"                            4        2
    "Offset"                      6        2
    "TTL"                        8        1
    "ProtoId"                    9        1
    CheckSum"                10        2
    "Source"                   12        4
    "Dest"                        16        4
</IP>

Once they have specified this, the tester should be able to create a packet
an assign values to the field, or receive a packet and parse out its
contents.
so a script should be able to say
p = read()
if p["ProtoId"] == 17:
    # do something here for UDP packets

Solution
    I have written a DLL  which can open/close/read/write to an ethernet
device. I've got it interfacing to Python. It can accept a buffer and return
a buffer. I've looked at socketmodule.c to get most of that figured out. I
assume what I need to do is build a dictionary whose keys are the field
names of a packet and then write a parser to fill in the values into the
dictionary. I also need something to parse the text file description.

If someone has done something like this before, or can point me to helpful
scripts and source, I would be grateful.
Thanks







More information about the Python-list mailing list