Created
January 26, 2022 10:22
-
-
Save knotman90/3a970484b97bb6e42ad7db606b881178 to your computer and use it in GitHub Desktop.
This file contains 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 struct | |
import sys | |
import binascii | |
assert len(sys.argv) ==3 | |
IP = sys.argv[1] | |
PORT = sys.argv[2] | |
print "Connecting to",IP, "on port", PORT | |
MCAST_GRP = IP | |
MCAST_PORT = int(PORT) | |
IS_ALL_GROUPS = True | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
if IS_ALL_GROUPS: | |
# on this port, receives ALL multicast groups | |
sock.bind(('', MCAST_PORT)) | |
else: | |
# on this port, listen ONLY to MCAST_GRP | |
sock.bind((MCAST_GRP, MCAST_PORT)) | |
mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY) | |
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) | |
while True: | |
# For Python 3, change next line to "print(sock.recv(10240))" | |
print sock.recv(10240) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
dump_udp_multicast.py MULTICAST_IP_ADDRESS PORT