繁体   English   中英

使用python套接字获取udp数据包的流量类别

[英]get traffic class of a udp packet using python socket

我想使用python套接字检索udp数据包的流量类别(TOS)。 以下代码在python中创建套接字,而我想检索类似于(java套接字中的getTrafficClass方法)的流量类。

 UDP_IP = '127.0.0.1' UDP_PORT = 8080 BUFFER_SIZE = 20 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind((UDP_IP, UDP_PORT)) data, address = s.recvfrom(BUFFER_SIZE) if data: print "received data:", data //I need to get the traffic class here. 

我认为在Java中没有像getTrafficClass()这样的就绪方法。 您可以读取IP层标头(位于UDP层标头下方)并进行解析,示例代码位于Sniffy.py https://github.com/OffensivePython/Sniffy/blob/master/Sniffy.pyhttps:// codingsec.net/2016/05/decoding-ip-layer-python/

[...]
def sniff(sock):
""" sniff a packet, parse its header and dump the sniffed data """
packet, address = sock.recvfrom(65565)
ipheader=ip(packet[:20])
ipheader.parse()
[...]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM