【问题标题】:get traffic class of a udp packet using python socket使用python套接字获取udp数据包的流量类
【发布时间】:2017-04-08 11:56:11
【问题描述】:

我想使用 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.

【问题讨论】:

    标签: python sockets network-programming


    【解决方案1】:

    我认为在 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()
    [...]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多