Last active
November 17, 2022 04:16
Dahua IP camera event listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import pycurl | |
connected = False | |
ap = argparse.ArgumentParser(description="Monitor event notifications from Dahua IP camera.") | |
ap.add_argument("-i", required=True, help="User ID", dest="id") | |
ap.add_argument("-p", required=True, help="User Password", dest="pw") | |
ap.add_argument("-a", required=True, help="Address for a camera", dest="addr") | |
ap.add_argument("-n", default=80, required=False, help="Port number for a camera", dest="port") | |
args = ap.parse_args() | |
def on_receive(data): | |
d = data.decode() | |
for line in d.split("\r\n"): | |
if "HTTP/1.1 200 OK" == line: | |
global connected | |
assert False == connected | |
connected = True | |
elif line.startswith("Code="): | |
print(line, flush=True) | |
if "__main__" == __name__: | |
url = "http://{0}:{1}@{2}:{3}/cgi-bin/eventManager.cgi?action=attach&codes=[VideoMotion]" | |
url = url.format(args.id, args.pw, args.addr, args.port) | |
c = pycurl.Curl() | |
c.setopt(pycurl.URL, url) | |
c.setopt(pycurl.CONNECTTIMEOUT, 10) | |
c.setopt(pycurl.TCP_KEEPALIVE, 1) | |
c.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_DIGEST) | |
c.setopt(pycurl.WRITEFUNCTION, on_receive) | |
c.perform() | |
c.close() | |
assert connected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do timestamping the output like the follwoing.