2012年10月17日

摘要: #dataAnalysis from Client def dataAnalysis(self): datafmt='<IIIIIIII' #定义struct 解包格式,相当协议格式 fmtLen = struct.calcsize(datafmt) #得到协议长度 while len(self._buffer) >= fmtLen: print "Buffer Length:%s" % len(self._buffer) (protocLength,) = \ ... 阅读全文
posted @ 2012-10-17 01:05 Vovolie 阅读(5216) 评论(0) 推荐(0) 编辑
摘要: 我们有时会将一个整数与IP地址进行互换,用python代码实现很简单将一个整数如2000000,变为一个IP地址的方式>>> import socket>>> import struct>>> int_ip = 123456789>>> ip = socket.inet_ntoa(struct.pack('I',socket.htonl(int_ip))) #int to ip address'7.91.205.21'>>> socket.ntohl(struct.unpa 阅读全文
posted @ 2012-10-17 00:28 Vovolie 阅读(44628) 评论(1) 推荐(1) 编辑

导航