通过特定的网络接口发送IPv6组播数据包 [英] Sending IPv6 multicast packets through a specific network interface

查看:439
本文介绍了通过特定的网络接口发送IPv6组播数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Windows通过python将IPv6 UDP数据包发送到本地网段上的所有节点.

I am trying to send IPv6 UDP packets to all of the nodes on the local network segment, in python, over Windows.

我的计算机中有几个网络接口,我想知道如何指定用于发送数据包的网络接口.

I have several network interfaces in my computer, and I want to know how to specify the network interface for sending the packets.

我尝试使用socket.sendto(无绑定)将数据包发送到多播地址ff02 :: 1(但没有绑定),但是数据包是在错误的网络接口中发送的.

I have tried sending the packets to the multicast address ff02::1, using socket.sendto (without binding), but the packets are sent in the wrong network interface.

任何想法如何指定网络适配器? (我读过有关BINDTODEVICE的信息,但它不适用于Windows,并且某些方法使用绑定方法来广播IP地址类,但仅适用于IPv4.)

Any idea how can I specify the network adapter? (I read about BINDTODEVICE, but it won't work on windows, and some methods using bind to broadcast IP address classes, but only for IPv4).

谢谢!

推荐答案

我不太喜欢以前的解决方案,因此我一直在寻找其他解决方案.

I didn't really like the previous solution, so I kept looking for others.

对我有用的第一个选项是将发送方套接字绑定到特定的网络接口地址.可以使用netifaces模块找到网络接口地址,而我使用的是

The first option that worked for me is to bind the sender socket to the specific network interface address. The network interfaces addresses can be found using netifaces module, and I used this helpful answer to specify the Ethernet address.

另一个可能有效的选项是IPV6_MULTICAST_IF选项-

Another option that might work is the IPV6_MULTICAST_IF option-

#x is the relevant interface index
sock.setsockopt(socket.IPPROTO_IPV6,socket.IPV6_MULTICAST_IF,x)

在Windows python 2.7中,应该添加一行

In Windows, python 2.7, one should add the line

socket.IPPROTO_IPV6=41

在此代码之前的

(因为相关的枚举没有很好地定义).

before this code (since the relevant enum is not well defined).

可以找到其他信息此处(Windows)或此处( Linux).

Additional information can be found here (Windows) or here (Linux).

尽管这似乎是一个更简单的解决方案,但是我并没有完全设法使其工作,并且不确定找到正确的接口索引的正确方法是什么(在Windows上,Linux有多种选择).

Although it seems like a simpler solution, I didn't completely managed to make it work, and not sure what is the proper way to find the right interface index (on Windows, Linux has several options).

这篇关于通过特定的网络接口发送IPv6组播数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆