[Twisted-Python] New user, help needed with raw UDP packets

Tommi Virtanen tv at tv.debian.net
Fri Apr 16 17:16:16 MDT 2004


Richard Taylor wrote:
> I am writing a UDP proxy/relay that needs to make detailed changes to the 
> internals of the UDP packets as they pass through. I intend to use 'Impacket' 
> to access the packet internals. One of the things that I need is to 'fake' 
> the destination address of packets leaving the proxy so that they look like 
> they have come from the original sender, Impacket has methods to do this for 
> 'raw' udp packets.
> 
> I think that I need to use a sub-class of ConnectedDatagramProtocol to send my 
> packets but the "self.transport.write" method takes only the packet payload 
> not the headers.

More to the point, normal UDP sockets cannot forge the source IP
address, as you seem to want to do.

You want "twisted.pair", RawUDPProtocol, and such things I sort of
half-wrote once. It's just about all there, you can make it work, but
it's not very complete and definitely not well documented.

doc/examples/pairudp.py shows a raw packet listener that reads from
a tuntap device and print out UDP packets with destination port 42.
You can also write such packets to the tuntap device, and the kernel
will route them from there on.

If you want to avoid tuntap, use packet sockets -- eunuchs (see
twisted.pair.tuntap docstring) has recvmsg() and sendmsg() wrappers that
should help.

For pcap integration, you're pretty much on your own.


My advice: don't try to do it with Python and Twisted unless you
already know how to do it in C :)




More information about the Twisted-Python mailing list