Search devices on all networks

旧城冷巷雨未停 提交于 2019-12-11 02:54:30

问题


I want to implement a code through which i can list-up upnp compliant media renderer devices connected on network. I googled for this and found following code on twisted website

When 2 networks(ethernet and wifi) are connected on my machine, it lists up devices of only one network.

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()

How to search devices of multiple networks ?

来源:https://stackoverflow.com/questions/24531442/search-devices-on-all-networks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!