Injecting raw TCP packets with Python

Posted by Evgeniy Arbatov on Stack Overflow See other posts from Stack Overflow or by Evgeniy Arbatov
Published on 2010-05-26T10:38:35Z Indexed on 2010/05/26 10:41 UTC
Read the original article Hit count: 414

Filed under:
|
|

Hello! What would be a suitable way to inject a raw TCP packet with Python? For example, I have the payload consisting of hexadecimal numbers and I want to send that sequence of hexadecimal numbers to a network daemon: so that if I choose to send 'abcdef', I see 'abcdef' on the wire too. But not '6162636566' as in the case of:

new = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
new.connect(('127.0.0.1', 9999))
new.send('abcdef')

Can I use Python's SOCK_RAW for this purpose? If so, can you give me an example of sending raw TCP packets with SOCK_RAW (since I did not get it working myself)

Thanks!

Evgeniy

© Stack Overflow or respective owner

Related posts about python

Related posts about tcp