socket send query

  • Thread starter connections cardiff
  • Start date
C

connections cardiff

hi all,

i want to mimic what another software program sends to a server.

if i look with a sniffer i can see the hex data that is being sent by
the real software program.

how can i send such data?

if i send the hex data values with a socket send then python assumes i
am trying to send a string of ascii characters and when i look at what
was sent in the sniffer i see the data i sent has been coverted into
their corresponding hex values. I want python to leave it alone and
send it.

i guess if my hex values had acsii equivalents i could send them and
they would be converted to the data i want but i dont think all my hex
data has acsii equivalents..

is there another way i should be doing this?

PS. IN CASE YOU DIDNT NOTICE I AM A NEWBIE!

many thanks

s
 
P

Peter Hansen

connections said:
if i send the hex data values with a socket send then python assumes i
am trying to send a string of ascii characters and when i look at what
was sent in the sniffer i see the data i sent has been coverted into
their corresponding hex values. I want python to leave it alone and
send it.

i guess if my hex values had acsii equivalents i could send them and
they would be converted to the data i want but i dont think all my hex
data has acsii equivalents..

is there another way i should be doing this?

It sounds to me like you have a string with two characters per byte
of intended data, where those characters are the digits in the hex
representation of the data. For example '45CE123F'. Is that right?

If that's the case, you are probably looking for the binascii module
and specifically its unhexlify() method. For example:
4

As you can see, the original 8-byte string with "hex" in it has
resulted in four bytes of actual data.

Another approach is to store your data as integers in a list, then
convert to a string:
d = [0x45, 0xce, 0x12, 0x3f]
d [69, 206, 18, 63]
''.join([chr(x) for x in d])
'E\xce\x12?'

As you can see, the same results as before but without starting with
a string containing the hex representation of the data.
PS. IN CASE YOU DIDNT NOTICE I AM A NEWBIE!

In that case, always consider posting small actual snippets of the
code you are trying to write, to provide useful context and help
give an idea at what level the responses should be targetted.

-Peter
 
E

Eddie Corns

i want to mimic what another software program sends to a server.
if i look with a sniffer i can see the hex data that is being sent by
the real software program.
how can i send such data?
if i send the hex data values with a socket send then python assumes i
am trying to send a string of ascii characters and when i look at what
was sent in the sniffer i see the data i sent has been coverted into
their corresponding hex values. I want python to leave it alone and
send it.
i guess if my hex values had acsii equivalents i could send them and
they would be converted to the data i want but i dont think all my hex
data has acsii equivalents..
is there another way i should be doing this?
PS. IN CASE YOU DIDNT NOTICE I AM A NEWBIE!
many thanks

This is one of the few instances where it's easier to do on Windows than
Unix. Do a google on "winpcap python" and see if you can find anything that
looks useful (there are quite a few). You should also be able to find
packages that do this, eg excalibur (IIRC) allows you to interactively create
packets (but it runs like a dog:(). Googling on "winpcap" will give you lots
of links.

Eddie
 
P

Paul McGuire

connections cardiff said:
hi all,

i want to mimic what another software program sends to a server.

if i look with a sniffer i can see the hex data that is being sent by
the real software program.

how can i send such data?

if i send the hex data values with a socket send then python assumes i
am trying to send a string of ascii characters and when i look at what
was sent in the sniffer i see the data i sent has been coverted into
their corresponding hex values. I want python to leave it alone and
send it.

i guess if my hex values had acsii equivalents i could send them and
they would be converted to the data i want but i dont think all my hex
data has acsii equivalents..

is there another way i should be doing this?

PS. IN CASE YOU DIDNT NOTICE I AM A NEWBIE!

many thanks

s
The struct module may be of help to you. Write up how your data packet
would look as a C struct, create the corresponding struct format string (see
the struct docs), then use the pack() and unpack() methods to convert your
Python data to and from the raw binary data form.

-- Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,516
Latest member
ChrisHibbs

Latest Threads

Top