A Python server that simulates a Hikvision device for testing purposes. It implements digest authentication and various ISAPI endpoints.
- Digest Authentication
- HTTPS Support
- Device Info Endpoint
- User Count Endpoint
- Event Notification System
- Python 3.8+
- pip (Python package installer)
- Clone the repository
git clone [your-repo-url]
cd hikvision-mock
- Install required dependencies
pip install requests
- Generate SSL certificates (required for HTTPS)
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
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"
}
python main.py
Using curl (ignore SSL verification since we're using self-signed certificates):
- Get Device Info
curl -k --digest -u admin:admin https://localhost/ISAPI/System/deviceInfo
- Get User Count
curl -k --digest -u admin:admin "https://localhost/ISAPI/AccessControl/UserInfo/Count?format=json"
- Get Notification Hosts
curl -k --digest -u admin:admin https://localhost/ISAPI/event/notification/httpHosts
- 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
- Test Host
curl -k --digest -u admin:admin \
-X POST \
https://localhost/ISAPI/event/notification/httpHosts/hik0/test
- Delete All Hosts
curl -k --digest -u admin:admin \
-X DELETE \
https://localhost/ISAPI/event/notification/httpHosts
.
├── README.md
├── main.py
├── hosts.json # Auto-generated file for storing hosts
├── cert.pem # Generated SSL certificate
└── key.pem # Generated SSL private key
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.
MIT License