Beispiel #1
0
 def Onvifdiscovery(self, retries=3):
     wsd = WSDiscovery()
     wsd.start()
     self.camlist = []
     resp = []
     a = 0
     while not resp and a < retries:
         ret = wsd.searchServices()
         a = a + 1
         for service in ret:
             #resp.append ({service.getEPR(): service.getXAddrs()[0]})
             tmp = urlparse(service.getXAddrs()[0])
             if (tmp.path.find("onvif")) == -1:
                 D("no onvif %s", tmp)
             else:
                 resp.append(service.getXAddrs()[0])
     self.camlist = resp
     print "RESP", resp
     if len(self.camlist) > 1:
         D("more than one onvif cameras available, selecting the first that answered"
           )
     selected = urlparse(self.camlist[0])
     self.camIP = selected.netloc
     self.cpath = selected.path
     self.conn = httplib.HTTPConnection(self.camIP)
     return selected.netloc, selected.path
Beispiel #2
0
 def Onvifdiscovery(self, retries=3):
     wsd = WSDiscovery()
     wsd.start()
     self.camlist = []
     resp = []
     a = 0
     while not resp and a < retries:
         ret = wsd.searchServices()
         a += 1
         for service in ret:
             #resp.append ({service.getEPR(): service.getXAddrs()[0]})
             tmp = urlparse(service.getXAddrs()[0])
             if (tmp.path.find("onvif")) == -1:
                 D("no onvif %s", tmp)
             else:
                 resp.append(service.getXAddrs()[0])
     self.camlist = resp
     print("RESP %s" % resp)
     if len(self.camlist) > 1:
         D("more than one onvif cameras available, selecting the first that answered")
     selected = urlparse(self.camlist[0])
     self.camIP = selected.netloc
     self.cpath = selected.path
     self.conn = httplib.HTTPConnection(self.camIP)
     return selected.netloc, selected.path
Beispiel #3
0
def main():
    wsd = WSDiscovery()
    wsd.start()

    ty1 = QName('http://schemas.xmlsoap.org/ws/2006/02/devprof', 'Device')
    ty2 = QName('http://schemas.microsoft.com/windows/2006/08/wdp/print', 'PrintDeviceType')

    sco = Scope('http://myscope')

    xaddr = 'http://uri4:8080/abc'

    wsd.publishService(types=[ty1, ty2], scopes=[], xAddrs=[xaddr])

    #raw_input('press [Enter]: ')

    server = wsgiref.simple_server.make_server('192.168.24.21', 8080, app)
    server.serve_forever()
Beispiel #4
0
def discover():
    # discovery method
    try:
        cameras = []
        ports = []
        wsd = WSDiscovery()
        wsd.start()
        ret = wsd.searchServices()
        print('discovered ', len(ret), ' services!')
        for service in ret:
            if 'onvif' in service.getXAddrs()[0]:
                ip = service.getXAddrs()[0]
                print(ip)
                ip = ip.split('.')
                ip = ip[len(ip) - 1].split(':')
                ip = ip[0].split('/')
                cameras.append(ip[0])
                port = service.getXAddrs()[0]
                if port.count(':') > 1:
                    port = port.split('.')
                    print(port)
                    port = port[len(port) - 1].split(':')
                    print(port)
                    port = port[len(port) - 1].split('/')
                    print(port)
                    port = port[0]
                    print(port)
                else:
                    port = 80
                ports.append(port)
                network = service.getXAddrs()[0]
                network = network.split('/')
                network = network[2].split('.')
                network = network[0] + '.' + network[1] + '.' + network[2]
        cameras.sort()
        print("cameras: ", cameras)
        print("network:", network)
        set = open(os.getcwd() + '/settings.py', 'w')
        set.write('net = ' + repr(network) + '\n' + 'cameras = ' +
                  repr(cameras) + '\n' + 'ports = ' + repr(ports))
        set.close()
        wsd.stop()
    except:
        return 'failed to discover services'
    return 'succ'
Beispiel #5
0
def discover():
    # discovery method
    try:
        cameras = []
        ports = []
        wsd = WSDiscovery()
        wsd.start()
        ret = wsd.searchServices()
        print('discovered ', len(ret), ' services!')
        for service in ret:
            if 'onvif' in service.getXAddrs()[0]:
                ip = service.getXAddrs()[0]
                print(ip)
                ip = ip.split('.')
                ip = ip[len(ip)-1].split(':')
                ip = ip[0].split('/')
                cameras.append(ip[0])
                port = service.getXAddrs()[0]
                if port.count(':') > 1:
                    port = port.split('.')
                    print(port)
                    port = port[len(port)-1].split(':')
                    print(port)
                    port = port[len(port)-1].split('/')
                    print(port)
                    port = port[0]
                    print(port)
                else:
                    port = 80
                ports.append(port)
                network = service.getXAddrs()[0]
                network = network.split('/')
                network = network[2].split('.')
                network = network[0] + '.' + network[1] + '.' + network[2]
        cameras.sort()
        print("cameras: ", cameras)
        print("network:" , network)
        set = open(os.getcwd() + '/settings.py', 'w')
        set.write('net = ' + repr(network) + '\n' + 'cameras = ' + repr(cameras) + '\n' + 'ports = ' + repr(ports))
        set.close()
        wsd.stop()
    except:
        return 'failed to discover services'
    return 'succ'
Beispiel #6
0
def discover():
    # discovery method
    try:
        cameras = []
        ports = []
        count = -1
        id = []
        wsd = WSDiscovery()
        wsd.start()
        ret = wsd.searchServices()
        print('discovered ', len(ret), ' services!')
        for service in ret:
            if 'onvif' in service.getXAddrs()[0]:
                ip = service.getXAddrs()[0]
                #print(ip)
                ip = ip.split('/')
                buf = ip[2].split(':')
                ip = buf[0]
                if len(buf) > 1:
                    port = buf[1]
                else:
                    port = '80'
                cameras = cameras + [[ip, port]]
                #print(cameras)
        cameras.sort()
        for each in cameras:
            count = count + 1
            id = id + [count]
        print("cameras: ", cameras)
        print("ids: ", id)
        set = open(os.getcwd() + '/settings.py', 'w')
        set.write('cameras = ' + repr(cameras) + '\n')
        set.write('ids = ' + repr(id))
        set.close()
        wsd.stop()
    except:
        return 'failed to discover services'
    return 'succ'
Beispiel #7
0
def discovery():
    ret = []
    for service in wsd.searchServices(types=[ONVIF_TYPE]):
        url = urlparse(service.getXAddrs()[0])
        scopes = service.getScopes()
        print(" Scopes:")
        for scope in scopes:
            print("  {})".format(repr(scope)))
        ret.append(url)

    return ret


if __name__ == "__main__":
    wsd = WSDiscovery()
    wsd.start()
    all_ipc = discovery()
    started = time.time()
    for cam in all_ipc:
        if cam.port is None:
            port = 80
        else:
            port = cam.netloc.split(':')[1]

        for auth_info in try_auth:
            try:
                IP_cam = ONVIFCamera(
                    cam.hostname, port, auth_info[0], auth_info[1],
                    '/home/jk/.local/lib/python3.5/site-packages/onvif/wsdl')
            except ONVIFError as e:
from WSDiscovery import WSDiscovery, QName, Scope

wsd = WSDiscovery()
wsd.start()

ttype = QName("abc", "def")

ttype1 = QName("namespce", "myTestService")
scope1 = Scope("http://myscope")
ttype2 = QName("namespace", "myOtherTestService_type1")
scope2 = Scope("http://other_scope")

xAddr = "localhost:8080/abc"
wsd.publishService(types=[ttype], scopes=[scope2], xAddrs=[xAddr])

#ret = wsd.searchServices(scopes=[scope1], timeout=10)
ret = wsd.searchServices()

for service in ret:
	print(service.getEPR() + ":" + service.getXAddrs()[0])
print("Done")

wsd.stop()

def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "t", ['timeout='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-t", "--timeout"):
            settings.TIMEOUT = int(arg)


if __name__ == "__main__":
    main()
    wsd = WSDiscovery()
    wsd.start()
    ret = wsd.searchServices(timeout=settings.TIMEOUT)
    lst = []
    for service in ret:
        d = {}
        types = ','.join(str(v) for v in service.getTypes())
        if 'onvif.org' in types:
            d['epr'] = service.getEPR()
            d['xaddr'] = service.getXAddrs()[::-1]
            d['types'] = types
            d['scopes'] = ','.join(str(v) for v in service.getScopes())
            lst.append(d)
    print json.dumps(lst)

    wsd.stop()