使用python构建tcp SYN数据包时如何设置tcp选项时间戳? [英] How to set the tcp option timestamp while building a tcp SYN packet using python?

查看:35
本文介绍了使用python构建tcp SYN数据包时如何设置tcp选项时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 tcp 选项中发送一个带有时间戳值的 tcp SYN 数据包.由于 tcp opts 应该以 32 位表示预先打包,谁能通过示例向我介绍如何设置 32 位数据包表示中的值.

I need to send a tcp SYN packet with timestamp value in tcp option. Since tcp opts should be prepacked in 32-bit representation, can anyone brief me how to set the value in 32 bit packet representaion with a example.

提前致谢

推荐答案

您应该能够使用 Scapy.在定义 TCP 层时,只需使用

You should be able to do that pretty easily with Scapy. When defining your TCP layer, just use

TCP(flags='S', options=[('Timestamp', (TSval, 0))])

其中 TSval 是您的时间戳值.如果要将结果数据包转换为其二进制表示,请对其调用 str().

where TSval is your timestamp value. If you want to convert the resultant packet to its binary representation, call str() on it.

在以后的数据包中,您可以根据 RFC 1323.

In future packets, you can replace the 0 with the appropriate TS echo reply per RFC 1323.

这篇关于使用python构建tcp SYN数据包时如何设置tcp选项时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆