def discover_cameras(scope=None, types='NetworkVideoTransmitter', capture=None): wsd = WSDiscovery(capture=capture) wsd.start() namespace = "http://www.onvif.org/ver10/network/wsdl" timeout = 10 if not scope and not types: svcs = wsd.searchServices(timeout=timeout) elif scope and not types: # we support giving just one scope, for now svcs = wsd.searchServices(scopes=[Scope(scope)], timeout=timeout) elif not scope and types: # we support giving just one scope, for now probetypes = [QName(namespace, types)] svcs = wsd.searchServices(types=probetypes, timeout=timeout) else: # we support giving just one scope, for now probetypes = [QName(namespace, types)] svcs = wsd.searchServices(scopes=[Scope(scope)], types=probetypes, timeout=timeout) cameras = [] for service in svcs: camera = {} url = urlparse(service.getXAddrs()[0]) port = url.port if not port: port = 80 camera['hostname'] = url.hostname camera['port'] = port camera['username'] = url.username camera['password'] = url.password #scopes = service.getScopes() #camera['scopes'] = scopes cameras.append(camera) wsd.stop() if len(cameras) > 0: print("Found {} cameras".format(len(cameras))) for camera in cameras: print(" {}:{}".format(camera['hostname'], camera['port'])) else: print("Did not find any cameras") return cameras
def run(scope=None, capture=None): ifname = get_valid_interface() if not ifname: logger.error("no interface found; use one of: %s", ", ".join(external_ifaces)) return ipaddr = get_ip_address(ifname) logger.debug("using %s interface with IPv4 address %s", ifname, ipaddr) wsd = WSDiscovery(capture=capture) wsd.start() if not scope: svcs = wsd.searchServices() else: # we support giving just one scope, for now svcs = wsd.searchServices(scopes=[Scope(scope)]) print("\nDiscovered:\n") for service in svcs: url = urlparse(service.getXAddrs()[0]) print(" address: %s" % url.netloc) print(" - %s\n" % "\n - ".join([str(s) for s in service.getScopes()])) wsd.stop()
def wsdiscovery() -> list[Service]: """Get ONVIF Profile S devices from network.""" discovery = WSDiscovery(ttl=4) discovery.start() services = discovery.searchServices( scopes=[Scope("onvif://www.onvif.org/Profile/Streaming")]) discovery.stop() return services
def discover(scope, address, port, loglevel, capture): "Discover services using WS-Discovery" logger = get_logger("ws-discovery", loglevel) with discovery(capture) as wsd: scopes = [Scope(scope)] if scope else [] svcs = wsd.searchServices(scopes=scopes, address=address, port=port) print("\nDiscovered:\n") for service in svcs: url = urlparse(service.getXAddrs()[0]) print(" address: %s" % url.netloc) print(" - %s\n" % "\n - ".join([str(s) for s in service.getScopes()]))
def run(scope=None, capture=None): wsd = WSDiscovery(capture=capture) wsd.start() if not scope: svcs = wsd.searchServices() else: # we support giving just one scope, for now svcs = wsd.searchServices(scopes=[Scope(scope)]) print("\nDiscovered:\n") for service in svcs: url = urlparse(service.getXAddrs()[0]) print(" address: %s" % url.netloc) print(" - %s\n" % "\n - ".join([str(s) for s in service.getScopes()])) wsd.stop()
def publish(scope, typename, address, port, loglevel, capture): "Publish services using WS-Discovery" logger = get_logger("ws-publishing", loglevel) with publishing(capture) as wsp: scopes = [Scope(scope)] if scope else [] try: proto, ns, name = typename.split(':') except: types = [] else: ns = ns[2:] types = [QName(proto, ns)] xAddrs = ["%s:%i" % (address, port)] if address else ['127.0.0.1'] svc = wsp.publishService(types, scopes, xAddrs)