Zeb*_*gle 2 python sockets udp mac-address multicast
我有一些代码通过UDP多播侦听"公告".我可以获取发件人的IP地址,但我真正需要的是发件人的MAC地址(因为IP地址可以并且将会改变).
有没有一种简单的方法在Python中执行此操作?
包含的代码段仅供参考,但可能不必要.
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((self.interface, MCAST_PORT))
# Tell API we are a multicast socket
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255)
# Tell API 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(self.interface));
data, addr = sock.recvfrom(1024)
Run Code Online (Sandbox Code Playgroud)
...