Skip to content

Instantly share code, notes, and snippets.

@robodhruv
Created August 27, 2017 13:30
Show Gist options
  • Save robodhruv/c91dbec2e631a74790d6d6436149aed5 to your computer and use it in GitHub Desktop.
Save robodhruv/c91dbec2e631a74790d6d6436149aed5 to your computer and use it in GitHub Desktop.
Capture UDP packets on a port in JSON-like format.
# This program captures UDP packets on port identified in the variable
# port_no. The port will remain blocked until the script is killed.
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
port_no = 5555;
class Echo(DatagramProtocol):
def datagramReceived(self, data, addr):
print("received %r from %s" % (data, addr))
self.transport.write(data, addr)
reactor.listenUDP(port_no, Echo())
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment