我想连接到里程碑 sdk 的管理服务器 (MIPSDK( 并获取 MIPSDK 的 imageServer 的令牌。我正在使用套接字,但不知道该怎么做。 这就是我到目前为止所做的
import ssl
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.x.xx', 443))
s = ssl.wrap_socket(s, keyfile=None, cert_reqs=ssl.CERT_NONE, certfile=None, server_side=False, ssl_version=ssl.PROTOCOL_TLS)
s.settimeout(10);
s.sendall("POST /ManagementServer/ServerCommandService.svc HTTP/1.1rnHost: 192.168.xx.xxrnAuthorization:Basic xxxxxxrnContent-Length: 2048rnrn")
new = s.recv(4096)
print new
甚至可以从python客户端登录到管理服务器吗? DotNet 中有内置类/功能,但我无法找到任何 python 实现。
环顾四周后,我终于设法从里程碑图像服务器获取令牌。
import ssl
import socket
import uuid
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('server-ip', 443))
v = uuid.uuid4()
s = ssl.wrap_socket(s, keyfile=None, cert_reqs=ssl.CERT_NONE, certfile=None, server_side=False, ssl_version=ssl.PROTOCOL_TLS)
data= '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Login xmlns="http://videoos.net/2/XProtectCSServerCommand"><instanceId>' + str(v) + '</instanceId><currentToken></currentToken></Login></soap:Body></soap:Envelope>'
data_len = len(data)
data_len = str(data_len)
s.sendall("POST /ManagementServer/ServerCommandService.svc HTTP/1.1rnHost: server-iprnContent-Type: text/xml; charset=utf-8rnAuthorization: Basic (base64 of '[BASIC]username:password')rnContent-Length: "+data_len+"rnSOAPAction: http://videoos.net/2/XProtectCSServerCommand/IServerCommandService/LoginrnConnection: closernrn" + data)
while True:
new = s.recv(4096)
if not new:
s.close()
break
print(new)
我正在使用基本身份验证。