def send_alive_pkg1(self): """ 发送类型一的心跳包 :return: """ pkg = b'\xff' pkg += md5(b'\x03\x01' + self.salt + self.pwd.encode('ascii')) # MD5_A pkg += b'\x00' * 3 pkg += self.auth_info pkg += struct.pack('!H', int(time.time()) % 0xFFFF) pkg += b'\x00' * 3 data, address = self._send_package(pkg, (self.server_ip, 61440)) if data[0] == 0x07: Log( logging.DEBUG, 0, "[DrCOM.send_alive_pkg1]:Successful sending heartbeat package type 1..." ) else: # 当收到的数据包没法识别的时候,标记当前状态已经为掉线状态 Log( logging.ERROR, 40, "[DrCOM.send_alive_pkg1]:Receive unknown packages content: {}". format(data)) self.alive_flag = False
def send_alive_pkg1(self): """ 发送类型一的心跳包 :return: """ pkg = b'\xff' pkg += md5(b'\x03\x01' + self.salt + self.pwd.encode('ascii')) # MD5_A pkg += b'\x00' * 3 pkg += self.auth_info pkg += struct.pack('!H', int(time.time()) % 0xFFFF) pkg += b'\x00' * 3 data, address = self._send_package(pkg, (self.server_ip, 61440)) if data[0] == 0x07: Log( logging.DEBUG, 0, "[DrCOM.send_alive_pkg1]:Successful sending heartbeat package type 1..." ) else: # 当收到的数据包没法识别的时候 exception = DrCOMException( "[DrCOM.send_alive_pkg1]:Receive unknown packages content...") exception.last_pkg = data raise exception
def _make_logout_package(self): # (0:3 4) Header = Code + Type + EOF + (UserName Length + 20) data = b'\x06\x01\x00' + int2hex_str(len(self.usr) + 20) # TODO MD5_A字段在BISTU版中的算法未知,但以下算法可以正常使用 # (4:19 16) MD5_A = MD5(Code + Type + Salt + Password) data += md5(b'\x06\x01' + self.salt + self.pwd.encode('ascii')) # (20:55 36) 用户名 data += self.usr.encode('ascii').ljust(36, b'\x00') # (56:56 1) 控制检查状态 data += CONTROL_CHECK_STATUS # (57:57 1) 适配器编号? data += ADAPTER_NUMBER # (58:63 6) (MD5_A xor MAC) data += int2hex_str( int.from_bytes(data[4:10], 'big') ^ int.from_bytes(self.mac, 'big')).rjust(6, b'\x00') data += self.auth_info return data
def _make_login_package(self): """ 构造登陆数据包 :return: """ # (0:3 4) Header = Code + Type + EOF + (UserName Length + 20) data = b'\x03\x01\x00' + int2hex_str(len(self.usr) + 20) # (4:19 16) MD5_A = MD5(Code + Type + Salt + Password) data += md5(b'\x03\x01' + self.salt + self.pwd.encode('ascii')) # (20:55 36) 用户名 data += self.usr.encode('ascii').ljust(36, b'\x00') # (56:56 1) 控制检查状态 data += CONTROL_CHECK_STATUS # (57:57 1) 适配器编号? data += ADAPTER_NUMBER # (58:63 6) (MD5_A xor MAC) data += int2hex_str( int.from_bytes(data[4:10], 'big') ^ int.from_bytes(self.mac, 'big')).rjust(6, b'\x00') # (64:79 16) MD5_B = MD5(0x01 + Password + Salt + 0x00 *4) data += md5(b'\x01' + self.pwd.encode('ascii') + self.salt + b'\x00' * 4) # (80:80 1) NIC Count data += b'\x01' # (81:84 4) 本机IP data += socket.inet_aton(self.ip) # (85:88 4) ip地址 2 data += b'\00' * 4 # (89:92 4) ip地址 3 data += b'\00' * 4 # (93:96 4) ip地址 4 data += b'\00' * 4 # (97:104 8) 校验和A data += md5(data + b'\x14\x00\x07\x0b')[:8] # (105:105 1) IP Dog data += IP_DOG # (106:109 4) 未知 data += b'\x00' * 4 # (110:141 32) 主机名 data += self.host_name.encode('ascii').ljust(32, b'\x00') # (142:145 4) 主要dns: 114.114.114.114 data += b'\x72\x72\x72\x72' # (146:149 4) DHCP服务器IP data += socket.inet_aton(DHCP_SERVER_IP) # (150:153 4) 备用dns:8.8.8.8 data += b'\x08\x08\x08\x08' # (154:161 8) 未知 data += b'\x00' * 8 data += b'\x94\x00\x00\x00' # (162:165 4) 未知 data += b'\x06\x00\x00\x00' # (166:169 4) OS major 不同客户端有差异 data += b'\x01\x00\x00\x00' # (170:173 4) OS minor 不同客户端有差异 data += b'\xb1\x1d\x00\x00' # (174:177 4) OS build 不同客户端有差异 data += b'\x02\x00\x00\x00' # (178:181 4) 未知 OS相关 # (182:213 32) 操作系统名称 data += "WINDOWS".encode('ascii').ljust(32, b'\x00') # (214:309 96) 未知 不同客户端有差异,BISTU版此字段包含一段识别符,但不影响登陆 data += b'\x00' * 96 # (310:311 2) data += AUTH_VERSION # (312:313 2) 未知 data += b'\x02\x0c' # (314:317 4) 校验和 data += checksum(data + b'\x01\x26\x07\x11\x00\x00' + self.mac) # (318:319 2) 未知 data += b'\x00\x00' # (320:325 6) 本机MAC data += self.mac # (326:326 1) auto logout / default: False data += b'\x00' # (327:327 1) broadcast mode / default : False data += b'\x00' # (328:329 2) 未知 不同客户端有差异 data += b'\x17\x77' return data