gpt4 book ai didi

multicast - 任何在指定的UDP端口上接收多播数据包的小程序?

转载 作者:行者123 更新时间:2023-12-04 22:21:57 26 4
gpt4 key购买 nike

我想调试一些多播问题,我希望有一些小程序/实用程序来显示传入的多播数据包。

从发送机器(A),我使用理查德史蒂文斯的 sock发送多播数据包(源端口=目标端口=7000)的程序(随他的TCP/IP Illustrated book Vol1提供),如下所示:

sock -u -b 7000 224.0.0.7 7000

在接收机器(B)上,我可以用 Wireshark 捕获非常发送的数据包,但是,相同的 sock在 B 上运行的命令不报告接收到任何内容。

然后,除了 Wireshark 是矫枉过正之外,我应该在 B 上使用什么程序来查看传入的多播数据包。

Linux 和 Windows 程序都受欢迎。

enter image description here

最佳答案

这是一个将打印传入数据的python脚本;

# Multicast client
# Adapted from: http://chaos.weblogs.us/archives/164

import socket

ANY = "0.0.0.0"
MCAST_ADDR = "224.0.0.7"
MCAST_PORT = 7000

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)

# Allow multiple sockets to use the same PORT number
sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)

# Bind to the port that we know will receive multicast data
sock.bind((ANY,MCAST_PORT))

# Tell the kernel that we want to add ourselves to a multicast group
# The address for the multicast group is the third param
status = sock.setsockopt(socket.IPPROTO_IP,
socket.IP_ADD_MEMBERSHIP,
socket.inet_aton(MCAST_ADDR) + socket.inet_aton(ANY))

# setblocking(0) is equiv to settimeout(0.0) which means we poll the socket.
# But this will raise an error if recv() or send() can't immediately find or send data.
sock.setblocking(0)

while 1:
try:
data, addr = sock.recvfrom(1024)
except socket.error as e:
pass
else:
print "From: ", addr
print "Data: ", data

关于multicast - 任何在指定的UDP端口上接收多播数据包的小程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15197569/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com