Skip to content

MounirGaiby/HikvisionAccessControlDevice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hikvision Device Mock Server

A Python server that simulates a Hikvision device for testing purposes. It implements digest authentication and various ISAPI endpoints.

Features

  • Digest Authentication
  • HTTPS Support
  • Device Info Endpoint
  • User Count Endpoint
  • Event Notification System

Prerequisites

  • Python 3.8+
  • pip (Python package installer)

Installation

  1. Clone the repository
git clone [your-repo-url]
cd hikvision-mock
  1. Install required dependencies
pip install requests
  1. Generate SSL certificates (required for HTTPS)
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes

Configuration

Default configuration is in the CONFIG object in main.py:

CONFIG = {
    "username": "admin",
    "password": "admin",
    "realm": "DS-2CD2342WD-I",
    "port": 443,
    "cert_file": "cert.pem",
    "key_file": "key.pem",
    "hosts_file": "hosts.json"
}

Running the Server

python main.py

Testing Endpoints

Using curl (ignore SSL verification since we're using self-signed certificates):

  1. Get Device Info
curl -k --digest -u admin:admin https://localhost/ISAPI/System/deviceInfo
  1. Get User Count
curl -k --digest -u admin:admin "https://localhost/ISAPI/AccessControl/UserInfo/Count?format=json"
  1. Get Notification Hosts
curl -k --digest -u admin:admin https://localhost/ISAPI/event/notification/httpHosts
  1. Add New Host
curl -k --digest -u admin:admin \
  -X POST \
  -H "Content-Type: application/xml" \
  -d '<?xml version="1.0" encoding="UTF-8"?>
<HttpHostNotification>
    <id>hik0</id>
    <url>/health</url>
    <protocolType>HTTP</protocolType>
    <parameterFormatType>JSON</parameterFormatType>
    <addressingFormatType>ipaddress</addressingFormatType>
    <ipAddress>127.0.0.1</ipAddress>
    <portNo>3001</portNo>
    <userName></userName>
    <httpAuthenticationMethod>none</httpAuthenticationMethod>
</HttpHostNotification>' \
  https://localhost/ISAPI/event/notification/httpHosts
  1. Test Host
curl -k --digest -u admin:admin \
  -X POST \
  https://localhost/ISAPI/event/notification/httpHosts/hik0/test
  1. Delete All Hosts
curl -k --digest -u admin:admin \
  -X DELETE \
  https://localhost/ISAPI/event/notification/httpHosts

Project Structure

.
├── README.md
├── main.py
├── hosts.json       # Auto-generated file for storing hosts
├── cert.pem        # Generated SSL certificate
└── key.pem         # Generated SSL private key

Security Note

This is a testing mock server. The included certificates (if any) and default credentials are for testing purposes only. Never use these in a production environment.

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages