<div dir="ltr"><div>Hi,<br><br>I am implementing a code through which i have to get devices connected to all network interfaces on my machine and list them .</div><div><br></div><div>For this, i am first getting the ip of all network interfaces and then sending m-search command on them.</div>


<div><br></div><div>After 2.5 seconds port is stopped to listen.</div><div><br></div><div>But it is giving me some assertion error. (I am connected to 2 interfaces -ethernet and wifi)<br></div><div><br></div><div>`Code:`</div>
<div><br></div><div>    class Base(DatagramProtocol):</div>

<div>        """ Class to send M-SEARCH message to devices in network and receive datagram</div><div>            packets from them</div><div>        """</div><div>        SSDP_ADDR = "239.255.255.250"</div>


<div>        SSDP_PORT = 1900</div><div>        MS = "M-SEARCH * HTTP/1.1\r\nHOST: {}:{}\r\nMAN: 'ssdp:discover'\r\nMX: 2\r\nST: ssdp:all\r\n\r\n".format(SSDP_ADDR, SSDP_PORT)</div><div>    </div><div>    def sendMsearch(self):</div>


<div>        """ Sending M-SEARCH message</div><div>        """</div><div>        ports = []</div><div>        for address in self.addresses:</div><div>            ports.append(reactor.listenUDP(0, self, interface=address))</div>


<div>            </div><div>        for port in ports:</div><div>            for num in range(4):</div><div>                port.write(Base.MS, (Base.SSDP_ADDR,Base.SSDP_PORT))</div><div>            reactor.callLater(2.5, self.stopMsearch, port) # MX + a wait margin</div>


<div><br></div><div><br></div><div>    def stopMsearch(self, port):</div><div>        """ Stop listening on port</div><div>        """</div><div>        port.stopListening()</div><div><br></div>


<div><br></div><div>`Error:`</div><div><span style="white-space:pre-wrap">  </span></div><div>    Traceback (most recent call last):</div><div><span style="white-space:pre-wrap">  </span>  File "work\find_devices.py", line 56, in sendMsearch</div>


<div><span style="white-space:pre-wrap">          </span>ports.append(reactor.listenUDP(0, self, interface=address))</div><div><span style="white-space:pre-wrap">      </span>  File "C:\Python27\lib\site-packages\twisted\internet\posixbase.py", line 374, in listenUDP</div>


<div><span style="white-space:pre-wrap">          </span>p.startListening()</div><div><span style="white-space:pre-wrap">       </span>  File "C:\Python27\lib\site-packages\twisted\internet\udp.py", line 172, in startListening</div>


<div><span style="white-space:pre-wrap">          </span>self._connectToProtocol()</div><div><span style="white-space:pre-wrap">        </span>  File "C:\Python27\lib\site-packages\twisted\internet\udp.py", line 210, in _connectToProtocol</div>


<div><span style="white-space:pre-wrap">          </span>self.protocol.makeConnection(self)</div><div><span style="white-space:pre-wrap">       </span>  File "C:\Python27\lib\site-packages\twisted\internet\protocol.py", line 709, in makeConnection</div>


<div><span style="white-space:pre-wrap">          </span>assert self.transport == None</div><div><span style="white-space:pre-wrap">    </span>AssertionError</div><div><br></div><div><br><br></div><div>This code worked:<br><br>def sendMsearch(self):

<div>        """ Sending M-SEARCH message<br></div><div>        """<br></div><div>        address = socket.gethostbyname(socket.gethostbyname())<br></div><div>        port = reactor.listenUDP(0, self, interface=address)<br>
        for num in range(4):<div>                port.write(Base.MS, (Base.SSDP_ADDR,Base.SSDP_PORT))</div><div>        reactor.callLater(2.5, self.stopMsearch, port) # MX + a wait margin</div><br></div><div><br></div><br>
<br></div><div>
Please tell what's wrong in code mentioned in the start of this mail and how to correct this.</div>
<div><br></div><div>I have also posted this code on stackoverflow , but didn't get any response</div><a href="http://stackoverflow.com/questions/24178580/send-m-search-packets-on-all-network-interfaces-using-twisted-module-in-python" target="_blank">http://stackoverflow.com/questions/24178580/send-m-search-packets-on-all-network-interfaces-using-twisted-module-in-python</a><br clear="all">

<br><div dir="ltr"><div>
</div></div>
</div>