gpt4 book ai didi

python-3.x - "installing"开泰结构Python

转载 作者:行者123 更新时间:2023-12-04 16:06:58 25 4
gpt4 key购买 nike

我需要有关在笔记本电脑上安装 Kaitai Struct 的帮助。

我安装了 python-kaitaistruct 并编译了网络文件。

但是我得到一个导入错误:

Traceback (most recent call last):
File "test2.py", line 1, in <module>
from ethernet_frame import *
File "/home/bene/python/ethernet_frame.py", line 15, in <module>
from ipv6_packet import Ipv6Packet
File "/home/bene/python/ipv6_packet.py", line 17, in <module>
from ipv4_packet import Ipv4Packet
File "/home/bene/python/ipv4_packet.py", line 17, in <module>
from ipv6_packet import Ipv6Packet
ImportError: cannot import name 'Ipv6Packet

我的文件夹是这样的:

insgesamt 76K
drwxr-xr-x 3 bene bene 330 19. Jan 16:03 .
drwx------ 24 bene bene 4,0K 19. Jan 16:06 ..
-rw-r--r-- 1 bene bene 42 5. Jan 12:38 country.py
-rw-r--r-- 1 bene bene 8,0K 5. Jan 12:09 dns_packet.py
-rw-r--r-- 1 bene bene 1,6K 5. Jan 12:09 ethernet_frame.py
-rw-r--r-- 1 bene bene 3,0K 5. Jan 12:09 icmp_packet.py
-rw-r--r-- 1 bene bene 7,7K 5. Jan 12:09 ipv4_packet.py
-rw-r--r-- 1 bene bene 2,7K 5. Jan 12:09 ipv6_packet.py
-rw-r--r-- 1 bene bene 6,4K 5. Jan 12:09 microsoft_network_monitor_v2.py
-rw-r--r-- 1 bene bene 7,0K 5. Jan 12:09 pcap.py
drwxr-xr-x 2 bene bene 180 5. Jan 12:12 __pycache__
-rw-r--r-- 1 bene bene 1,1K 5. Jan 12:09 tcp_segment.py
-rw-r--r-- 1 bene bene 518 5. Jan 12:32 test1.py
-rw-r--r-- 1 bene bene 596 19. Jan 15:56 test2.py
-rw-r--r-- 1 bene bene 667 5. Jan 12:38 test.py
-rw-r--r-- 1 bene bene 880 5. Jan 12:09 udp_datagram.py
-rw-r--r-- 1 bene bene 986 5. Jan 12:09 windows_systemtime.py

和我执行的文件:

from ethernet_frame import *
import socket

s = socket.socket(socket.AF_PACKET,socket.SOCK_RAW,socket.ntohs(3))

def network(buf):
io = BytesIO(buf)
ksio = KaitaiStream(io)
pkt = EthernetFrame(ksio)
dummy = pkt.ipv4_body.src_ip_addr
print(dummy)

while True:
p = s.recvfrom(65565)
network(p)

谁能帮帮我,也许我安装错了?或者如何安装和使用它的完整指南会很酷:DD

谢谢<3

最佳答案

我有一个类似的问题,在检查编译器创建的 .py 文件后,我发现编辑导入序列解决了这个问题。示例:

import ipv4_packet 导致了与您相同的错误。

我检查了 ipv4_packet.py,它有一个导入语句 from ipv6_packet import Ipv6Packet

        # This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

from pkg_resources import parse_version
from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO
from enum import Enum


if parse_version(ks_version) < parse_version('0.7'):
raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))

from udp_datagram import UdpDatagram
from tcp_segment import TcpSegment
from ipv6_packet import Ipv6Packet
from icmp_packet import IcmpPacket

class Ipv4Packet(KaitaiStruct):

class ProtocolEnum(Enum):

ipv6_packet 尝试从 ipv4_packet 导入类:from ipv4_packet import Ipv4Packet,并导致导入错误。如果行 (ipv4_packet .py):

from udp_datagram import UdpDatagram
from tcp_segment import TcpSegment
from ipv6_packet import Ipv6Packet
from icmp_packet import IcmpPacket

被移动到类定义之后没有错误。

今天早上第一次玩 Kaitai Struct,我确信这不需要手动完成,我/我们正在做的编译中有一个问题,但如果你只是想拥有,这是可行的快速播放。

关于python-3.x - "installing"开泰结构Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48344121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com