在Python中获取传入UDP数据包的TTL [英] Getting TTL of incoming UDP packet in Python

查看:1166
本文介绍了在Python中获取传入UDP数据包的TTL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python中的套接字模块进行一些基本的UDP客户端 - 服务器通信。我需要做的很简单:客户端向服务器发送数据包,服务器用客户端的公共IP地址,端口和代表UDP数据包到达服务器时的TTL的数字进行回答。这是我的主要问题:有没有办法用recvfrom()左右接收数据包,并读取它到达我的服务器时的TTL值?

I'm using the socket module in Python to do some basic UDP client-server communication. What I would need to do is quite simple: client sends server a packet, server answers with client's public ip address, port and a number representing the TTL the UDP packet had when it got to the server. This is my main problem: is there any way to recieve a packet with recvfrom() or so, and read the TTL value it had when it reached my server?

谢谢你非常喜欢!

Matteo Monti

Matteo Monti

推荐答案

我想你想要的到setsockopt(IP_RECVTTL),然后使用recvmsg()。但是Python似乎没有在其标准库中使用recvmsg(参见 http://bugs.python.org/issue6560 )。因此,您可能需要编写一个可由Python导入的小型C或C ++共享库,它可以满足您的需求。或者尝试使用第一页链接的补丁。

I think you want to setsockopt(IP_RECVTTL) and then use recvmsg(). But Python doesn't seem to have recvmsg in its standard libraries (see http://bugs.python.org/issue6560). So probably you will need to write a small C or C++ shared library which is importable by Python and which does what you want. Or maybe try using the patches from page I linked.

这篇关于在Python中获取传入UDP数据包的TTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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