Injecting raw TCP packets with Python
- by Evgeniy Arbatov
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