コード例 #1
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
コード例 #2
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()
コード例 #3
0
    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)