Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python IP协议字段号到字符串_Python_Scapy - Fatal编程技术网

Python IP协议字段号到字符串

Python IP协议字段号到字符串,python,scapy,Python,Scapy,使用scapy,如何从packetproto字段上的数字中获取一个带有IP协议名称的字符串 例如,将6转换为“TCP”。Scapy非常棒,但是文档中还有很多需要改进的地方。这项工作: from scapy.all import * def ip_proto(pkt): proto_field = pkt.get_field('proto') return proto_field.i2s[pkt.proto] x = IP() / TCP() print ip_proto(x)

使用scapy,如何从packetproto字段上的数字中获取一个带有IP协议名称的字符串


例如,将6转换为“TCP”。

Scapy非常棒,但是文档中还有很多需要改进的地方。这项工作:

from scapy.all import *

def ip_proto(pkt):
    proto_field = pkt.get_field('proto')
    return proto_field.i2s[pkt.proto]

x = IP() / TCP()
print ip_proto(x)

请提供一些代码,向我们展示您的研究和您为解决此问题所做的努力。谢谢。为了完成此操作,您需要一个IP数据包来使用此方法。例如,如果您有一个以太网数据包,您需要首先获取IP数据包:
IP协议(eth\u packet[IP])
为了更通用,当您获取一个以太网数据包时,使用
payload
指定下一层:
IP协议(eth\u packet.payload)
,但您应该首先确认有效负载存在