我一直试图通过我创建的套接字发送数据包
def createPacket (id):
header = Struct.pack('bbHHh', 0, 0, 0, id, 1)
data = ''
header = Struct.pack('bbHHh' , 0,0,socket.htons(chksum(header+data)),id ,1)
return header+data
def send_reply(dest,timeout=1):
sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.getprotobyname('icmp'))
pkt_id = int((id(timeout) * random.random()) / 65535)
packet = createPacket(pkt_id)
send = sock.sendto(packet ,dest)
,我有一种计算校验和的方法。
但是当我运行它时,python3解释器给了我这个错误:
TypeError: descriptor 'pack' requires a 'Struct' object but received a 'str'
我不知道如何处理。