我想连接到里程碑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.1\r\nHost: 192.168.xx.xx\r\nAuthorization:Basic\ xxxxxx\r\nContent-Length: 2048\r\n\r\n")
new = s.recv(4096)
print new
是否甚至可以从python客户端登录管理服务器? DotNet中有内置的类/功能,但是我找不到任何python实现。
答案 0 :(得分:0)
环顾四周之后,我终于设法从里程碑imageServer获取了令牌。
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.1\r\nHost: server-ip\r\nContent-Type: text/xml; charset=utf-8\r\nAuthorization: Basic (base64 of '[BASIC]\username:password')\r\nContent-Length: "+data_len+"\r\nSOAPAction: http://videoos.net/2/XProtectCSServerCommand/IServerCommandService/Login\r\nConnection: close\r\n\r\n" + data)
while True:
new = s.recv(4096)
if not new:
s.close()
break
print(new)
我正在使用基本身份验证。