Created
May 14, 2015 13:37
-
-
Save flyte/ed8817ab6454f38e07dd to your computer and use it in GitHub Desktop.
Listen for and print out the contents of UDP packets received on a specific port.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import argparse | |
if __name__ == "__main__": | |
p = argparse.ArgumentParser() | |
p.add_argument("port", type=int) | |
args = p.parse_args() | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
sock.bind(("0.0.0.0", args.port)) | |
while True: | |
data, addr = sock.recvfrom(1024) | |
print "Packet received from %s: %s" % (addr, data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment