python练习题【二】

问题:使用struct来构建tcp数据包

 

 

#coding=utf-8
from random import randint
import struct
#源端口
source_port = randint(1,65535);
#目的端口
dst_port = 23;
#32位确认序号
ack_sn=0;
#32序号
sn=randint(1,65535*65535);
#数据包窗口
windows=4096
data=struct.pack('>HHIIBBH',source_port,dst_port,sn,ack_sn,80,2,windows);
hd = open('data.bin','wb');
hd.write(data);
hd.close();

  

 

posted on 2020-02-24 23:31  孤灯引路人  阅读(207)  评论(0编辑  收藏  举报

导航