Example #1
0
def FlashXM(cmd):
    cam = DVRIPCam(GetIP(devices[cmd[1]]["HostIP"]), "admin", cmd[2])
    if cam.login():
        cmd[4](_("Auth success"))
        cam.upgrade(cmd[3], 0x4000, cmd[4])
    else:
        cmd[4](_("Auth failed"))
Example #2
0
    def __init__(self, address, user, password):
        self.dvrip = DVRIPCam(address, user, password)
        loginok = self.dvrip.login()
        if not loginok:
            raise ValueError('Login failed')

        self.onvif = ONVIFCamera(address, 8899, user, password,
                                 '../venv/lib/python3.7/site-packages/wsdl/')
        self.onvif_media = self.onvif.create_media_service()
Example #3
0
def jobWrapper():
    global cam
    log('Logging in to camera ' + camIp + '...')
    cam = DVRIPCam(camIp)
    if cam.login():
        log('done')
    else:
        raise SomethingIsWrongWithCamera('Cannot login')
    syncTime()
    theActualJob()
Example #4
0
def open_telnet(host_ip, port, **kwargs):
    make_telnet = kwargs.get('telnet', False)
    make_backup = kwargs.get('backup', False)
    user = kwargs.get('username', 'admin')
    password = kwargs.get('password', '')

    cam = DVRIPCam(host_ip, user=user, password=password)
    if not cam.login():
        print(f"Cannot connect {host_ip}")
        return
    upinfo = cam.get_upgrade_info()
    hw = upinfo["Hardware"]
    print(f"Modifiying camera {hw}")
    sysinfo = cam.get_system_info()
    swver = extract_gen(sysinfo["SoftWareVersion"])
    print(f"Firmware generation {swver}")

    desc = {
        "Hardware": hw,
        "DevID": f"{swver}1001000000000000",
        "CompatibleVersion": 2,
        "Vendor": "General",
        "CRC": "1ce6242100007636",
    }
    upcmd = []
    if make_telnet:
        upcmd.append(cmd_telnetd(port))
    elif make_backup:
        upcmd = cmd_backup()
    else:
        upcmd.append(cmd_armebenv(swver))
    desc['UpgradeCommand'] = upcmd
    add_flashes(desc, swver)

    zipfname = "upgrade.bin"
    make_zip(zipfname, json.dumps(desc, indent=2))
    cam.upgrade(zipfname)
    cam.close()
    os.remove(zipfname)

    if make_backup:
        print("Check backup")
        return

    if not make_telnet:
        port = 23
        print("Waiting for camera is rebooting...")

    for i in range(10):
        time.sleep(4)
        if check_port(host_ip, port):
            tport = f" {port}" if port != 23 else ''
            print(f"Now use 'telnet {host_ip}{tport}' to login")
            return

    print("Something went wrong")
    return
Example #5
0
class Camera:
    def __init__(self, address, user, password):
        self.dvrip = DVRIPCam(address, user, password)
        loginok = self.dvrip.login()
        if not loginok:
            raise ValueError('Login failed')

        self.onvif = ONVIFCamera(address, 8899, user, password,
                                 '../venv/lib/python3.7/site-packages/wsdl/')
        self.onvif_media = self.onvif.create_media_service()

    def step(self, direction, sleep=0.1):
        assert direction in ('DirectionUp', 'DirectionDown', 'DirectionLeft',
                             'DirectionRight')
        self.dvrip.ptz(direction, preset=65535)  # move
        time.sleep(sleep)
        self.dvrip.ptz(direction, preset=-1)  # Stop

    def get_snapshot_uri(self):
        for profile in ('000', '001', '002'):
            snapshot_uri = self.onvif.media.GetSnapshotUri('000').Uri
            logging.info("Snapshot uri is: %s for profile %s", snapshot_uri,
                         profile)
        return snapshot_uri

    def acquire(self, filename=None):
        if filename is None:
            filename = datetime.datetime.now().isoformat() + '.jpg'

        logging.info('Saving file to %s', filename)

        hdr = {'Accept': '*/*'}
        with open(filename, 'wb') as fout:
            '''
            r = requests.get(self.get_snapshot_uri(), stream=True, headers=hdr)
            if r.status_code == 200:
                with open(path, 'wb') as f:
                    r.raw.decode_content = True
                    shutil.copyfileobj(r.raw, fout)
            '''
            response = urlopen(self.get_snapshot_uri())
            data = response.read()
            fout.write(data)

    def close(self):
        self.dvrip.close()
Example #6
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
from dvrip import DVRIPCam
from time import sleep
import json

host_ip = "192.168.0.100"
if len(sys.argv) > 1:
    host_ip = str(sys.argv[1])

cam = DVRIPCam(host_ip, user="******", password="******")

if cam.login():
    print("Success! Connected to " + host_ip)
else:
    print("Failure. Could not connect.")

info = cam.get_info("fVideo.OSDInfo")
print(json.dumps(info, ensure_ascii=False))
info["OSDInfo"][0]["Info"] = [u"Тест00", "Test01", "Test02"]
# info["OSDInfo"][0]["Info"][1] = ""
# info["OSDInfo"][0]["Info"][2] = ""
# info["OSDInfo"][0]["Info"][3] = "Test3"
info["OSDInfo"][0]["OSDInfoWidget"]["EncodeBlend"] = True
info["OSDInfo"][0]["OSDInfoWidget"]["PreviewBlend"] = True
# info["OSDInfo"][0]["OSDInfoWidget"]["RelativePos"] = [6144,6144,8192,8192]
cam.set_info("fVideo.OSDInfo", info)
# enc_info = cam.get_info("Simplify.Encode")
# Alarm example
def alarm(content, ids):
Example #7
0
    new_ip_dec = str(sys.argv[2])
    if new_ip_dec == old_ip:
        exit(0)
    if new_ip_dec == "192.168.1.10":
        new_ip_hex = "0x0A01A8C0"
    elif new_ip_dec == "192.168.1.11":
        new_ip_hex = "0x0B01A8C0"
    elif new_ip_dec == "192.168.1.12":
        new_ip_hex = "0x0C01A8C0"
    elif new_ip_dec == "192.168.1.13":
        new_ip_hex = "0x0D01A8C0"
    elif new_ip_dec == "192.168.1.14":
        new_ip_hex = "0x0E01A8C0"
    elif new_ip_dec == "192.168.1.15":
        new_ip_hex = "0x0F01A8C0"
    cam = DVRIPCam(old_ip, "admin")
    if cam.login():
        # cam.set_info('NetWork.NetDHCP[0].Enable', "False")
        # cam.set_info('IPAdaptive.IPAdaptive', "False")
        # print(cam.get_info('IPAdaptive.IPAdaptive'))
        # print(cam.get_info('NetWork'))
        # print(cam.get_info('NetWork.NetDHCP[0].Enable'))
        cam.set_info('NetWork.NetCommon.HostIP', new_ip_hex)
        cam.close()
    # cam = DVRIPCam(new_ip_dec, "admin", "")
    # if cam.login():
    #     print(cam.get_info('NetWork.NetDHCP[0].Enable'))
    #     cam.close()

except:
    exit(1)
Example #8
0
import socket
import json
import os
import xmltodict
import datetime
import subprocess
import time
from dvrip import DVRIPCam
import cv2
import requests

cam = DVRIPCam("192.168.1.102", "admin", "")
TIMEOUT = 30

cam_door_link = ""
cam_room_link = ""
cam_cat_link = ''
photo_folder = "/photos/STORAGE/"

token = "611822792:AAFV2bYAdgqpGKACeheObAaz7jtzI1Y30qM"
chat_id = "274625481"

# stringa = '<event><title>motion_dect</title><time>2020-04-23T22:24:18</time><status>start</status></event>'
# text = xmltodict.parse(stringa)
# print(text['event'])

door_cam_ID = ''
room_cam_ID = ''
yard_cam_ID = ''

Example #9
0
import sys
from dvrip import DVRIPCam
from time import sleep

host_ip = '192.168.2.108'
if len(sys.argv) > 1:
    host_ip = str(sys.argv[1])

cam = DVRIPCam(host_ip)
cam.connect()

if cam.login():
    print "Success! Connected to " + host_ip
else:
    print "Failure. Could not connect."

enc_info = cam.get_info(1042, "Simplify.Encode")

cam.get_encode_info()
sleep(1)
cam.get_camera_info()
sleep(1)

enc_info['Simplify.Encode'][0]['ExtraFormat']['Video']['FPS'] = 20
cam.set_info(1040, "Simplify.Encode", enc_info)
sleep(2)
print(cam.get_info(1042, "Simplify.Encode"))
cam.close()