尝试在 python 中使用 Kaitai Struct 读取 pcap。
我已经从文件创建了 pythonpcap.ksy
文件
$ ./bin/kaitai-struct-compiler -t python --outdir xx formats/network/pcap.ksy
$ ls xx
ethernet_frame.py ipv6_packet.py __pycache__
icmp_packet.py packet_ppi.py tcp_segment.py
ipv4_packet.py pcap.py udp_datagram.py
PYTHONPATH 设置为 xx 目录。现在,如果我运行一个简单的单行脚本来检查我是否可以加载模块
from pcap import Pcap
我收到这个错误
$ python3 try.py
Traceback (most recent call last):
File "try.py", line 1, in <module>
from pcap import Pcap
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/pcap.py", line 11, in <module>
from packet_ppi import PacketPpi
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/packet_ppi.py", line 11, in <module>
from ethernet_frame import EthernetFrame
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/ethernet_frame.py", line 11, in <module>
from ipv6_packet import Ipv6Packet
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/ipv6_packet.py", line 12, in <module>
from ipv4_packet import Ipv4Packet
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/ipv4_packet.py", line 13, in <module>
from ipv6_packet import Ipv6Packet
ImportError: cannot import name 'Ipv6Packet'
我的阅读是 python 路径是好的,python 模块正在从 pacp、以太网、ipv6 到 ipv4 沿着链向下工作。然后 ipv4 尝试再次加载 ipv6 并且脚本失败了。
我认为代码正在触发导入循环。
有人知道我在做什么错吗?