title: how to discovery Onvif device with python
body: <p>In my project, I need to find a camera device that uses the onvif.
  I get the desired results through multicast-socket, but it's not as expected.</p>
  <p>This is my code:</p>
  <pre><code>my_ip = &quot;192.168.1.88&quot;
  mul_ip = &quot;239.255.255.250&quot;
  mul_port = 37020
  xml_str = '&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;Envelope xmlns:tds=&quot;http://www.onvif.org/ver10/device/wsdl&quot; xmlns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;&gt;&lt;Header&gt;&lt;wsa:MessageID xmlns:wsa=&quot;http://schemas.xmlsoap.org/ws/2004/08/addressing&quot;&gt;uuid:05ebeac7-ab22-4f3c-ac10-71a6bed6788b&lt;/wsa:MessageID&gt;&lt;wsa:To xmlns:wsa=&quot;http://schemas.xmlsoap.org/ws/2004/08/addressing&quot;&gt;urn:schemas-xmlsoap-org:ws:2005:04:discovery&lt;/wsa:To&gt;&lt;wsa:Action xmlns:wsa=&quot;http://schemas.xmlsoap.org/ws/2004/08/addressing&quot;&gt;http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe&lt;/wsa:Action&gt;&lt;/Header&gt;&lt;Body&gt;&lt;Probe xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://schemas.xmlsoap.org/ws/2005/04/discovery&quot;&gt;&lt;Types&gt;tds:Device&lt;/Types&gt;&lt;Scopes /&gt;&lt;/Probe&gt;&lt;/Body&gt;&lt;/Envelope&gt;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;Envelope xmlns:dn=&quot;http://www.onvif.org/ver10/network/wsdl&quot; xmlns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;&gt;&lt;Header&gt;&lt;wsa:MessageID xmlns:wsa=&quot;http://schemas.xmlsoap.org/ws/2004/08/addressing&quot;&gt;uuid:6604dcab-ae78-4b39-86af-71a3c71884a6&lt;/wsa:MessageID&gt;&lt;wsa:To xmlns:wsa=&quot;http://schemas.xmlsoap.org/ws/2004/08/addressing&quot;&gt;urn:schemas-xmlsoap-org:ws:2005:04:discovery&lt;/wsa:To&gt;&lt;wsa:Action xmlns:wsa=&quot;http://schemas.xmlsoap.org/ws/2004/08/addressing&quot;&gt;http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe&lt;/wsa:Action&gt;&lt;/Header&gt;&lt;Body&gt;&lt;Probe xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://schemas.xmlsoap.org/ws/2005/04/discovery&quot;&gt;&lt;Types&gt;dn:NetworkVideoTransmitter&lt;/Types&gt;&lt;Scopes /&gt;&lt;/Probe&gt;&lt;/Body&gt;&lt;/Envelope&gt;'
  
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255)
  s.bind((my_ip, mul_port))
  s.setsockopt(
      socket.IPPROTO_IP,
      socket.IP_ADD_MEMBERSHIP,
      socket.inet_aton(mul_ip) + socket.inet_aton(my_ip)
  )
  
  s.setblocking(False)
  
  s.sendto(xml_str.encode(), (mul_ip, mul_port))
  while True:
      try:
          data, address = s.recvfrom(65535)
          print('address: ', address)
          print('data: ', data)
      except Exception as e:
          pass
  </code></pre>
  <p>This result returns the original <code>xml_str</code> input and my own IP/PORT(<code>my_ip</code> <code>mul_port</code>).</p>
  <hr />
  <p>I want to understand two issues:</p>
  <ol>
  <li>Is there anything wrong with this python multicast-socket?</li>
  <li>Are there other ways to get onvif devices? I used python-ws-discovery (<a href="https://github.com/andreikop/python-ws-discovery" rel="nofollow noreferrer">https://github.com/andreikop/python-ws-discovery</a>), but it doesn't work
  on Windows10 OS.</li>
  </ol>