资源简介
util.py
It is my work-code. I hope it is used for you. OK, this's all.
![](http://www.nz998.com/pic/67449.jpg)
代码片段和文件信息
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import base
import simplejson as json
import logger as log
import timesocket
# type : string
# content : list
def request(type content logger):
if len(content) > 0:
total_len = 0
group = []
for val in content:
group_len = len(val)
group_content = base.toHex(val)
total_len = total_len + group_len + 2
group.append((base.dec2hex(socket.htons(group_len)) group_content))
length = base.dec2hex(socket.htonl(total_len))
else:
length = “00000000“
command = “FFFFFFFF“ + “01000001“ + type + length + “FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF“
if len(content) > 0:
logger.info(group)
for kv in group:
command = command + k + v
logger.info(“send command : %s“ % command)
return command
def recv_data(buf logger):
version = buf[8:16]
command_type = buf[16:24]
logger.info(“version: %s type: %s“ % (version command_type))
length = base.hex2decl(buf[24:32])
l = length
k = 64
group = []
while l > 0:
i = k
j = k + 4
group_len = base.hex2decs(buf[i:j])
m = j + group_len * 2
group_content = base.toStr(buf[j:m])
logger.info(“receive content : %s “ % group_content)
group.append(group_content)
k = m
l = l - 2 - group_len
return group
if __name__ == “__main__“:
logger = log.log_control(‘/home/work/var/www/htdocs/lab/log/test_‘ + time.strftime(‘%y_%m_%d‘) + ‘.log‘)
s = ‘FFFFFFFF01000001FFFFFFFF5D000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5B0053302D4531312D45567C7CB1A3B4E6C4A3BFE9363230357C3123414C5FD0E9C4E2C9E8B1B87C536574506172616D2064656D6F206576656E747C337C377C323030392D31322D30322030393A35353A31327C‘
#recv_data(s logger)
#print base.toStr(s[68:])
content = [“S0-ST|1“ “S0-LS|1“]
command = request(“FFFFFFFF“ content logger)
recv_data(command logger)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1789 2018-09-18 16:43 util.py
- 上一篇:label.png为16位转8位python代码
- 下一篇:Python调用QQ截图
评论
共有 条评论