搜索所有网络上的设备

时间:2014-07-02 12:45:40

标签: python-2.7 udp twisted upnp ssdp

我想实现一个代码,通过该代码我可以列出连接在网络上的兼容媒体渲染器设备。我用Google搜索并在twisted website

上找到了以下代码

当我的机器上连接了2个网络(以太网和wifi)时,它会列出只有一个网络的设备。

code

from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
import re

class MulticastPingPong(DatagramProtocol):
    XMLNS = "{urn:schemas-upnp-org:device-1-0}"

    def startProtocol(self):
        # Join the multicast address, so we can receive replies:
        self.transport.joinGroup("239.255.255.250")

    def datagramReceived(self, datagram, address):
        if(re.search("USN:.*MediaRenderer", datagram, flags=re.IGNORECASE)):
            # code to print friendly name

reactor.listenMulticast(1900, MulticastPingPong(), listenMultiple=True)
reactor.run()

如何搜索多个网络的设备?

0 个答案:

没有答案
相关问题