在https://github.com/likaci/mercury-ipc-control修改,替换掉了requests,我是最近几天骗多多入手的,分析了下web登录,没用到rsa加密的相关信息,所以删掉了,使用urllib代替了requests,兼容python 2、python 3。
用户名、密码、摄像头URL写在脚本内,请自行修改。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import base64
import json
import sys
if sys.version > '3':
import urllib.request as request
else:
import urllib2 as request
def get_stok(url, username, password):
tmp = json.dumps({"method":"do","login":{"username":username,"password":password}}).encode("utf-8")
req = request.Request(url=url, data=tmp)
result = request.urlopen(req).read()
result = json.loads(result)
key = result['stok']
return key
def run_cmd (base_url, data, stok):
url = base_url + "/stok=" + stok + "/ds"
req = request.Request(url=url, data=data.encode("utf-8"))
request.urlopen(req)
if __name__ == '__main__':
username = "XXXXXX"
password = "XXXXXX"
base_url = "http://XXX.XXX.XXX.XXX"
data = str(sys.argv[1])
stok = get_stok(base_url, username, password)
run_cmd(base_url, data, stok)
|