导入错误:无法从部分初始化的模块'scapy.ansmachine'导入名称'AnsweringMachine'



当我使用scapy.layers.inet.IP包时,结果显示importterror:无法从部分初始化模块scapy.ansmachine中导入名称AnsweringMachine .

我很困惑,这是我的python演示。

import hashlib
import time
from scapy.layers.inet import ICMP, IP
from scapy.sendrecv import sr1
SUCCESS = 100001
FAILURE = 100002
def random_str_byte():
temp = hashlib.md5()
temp.update(bytes(str(time.time()), encoding='utf-8'))
result = temp.hexdigest()
return bytes(result, encoding='utf-8')

def ping(target_ip):
package = IP(dst=target_ip)/ICMP()/random_str_byte()
result = sr1(package, timeout=3, verbose=False)
if result:
return target_ip, SUCCESS
else:
return target_ip, FAILURE

if __name__ == '__main__':
a = ping('XX.XX.XX.XX')
print(a)

错误信息是

Traceback (most recent call last):
File "/Users/zhaozihao/PycharmProjects/MachineProject/api/PingTest.py", line 6, in <module>
from scapy.layers.inet import ICMP, IP
File "/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/layers/inet.py", line 22, in <module>
from scapy.ansmachine import AnsweringMachine
File "/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/ansmachine.py", line 20, in <module>
from scapy.sendrecv import send, sniff
File "/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/sendrecv.py", line 61, in <module>
import scapy.route  # noqa: F401
File "/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/route.py", line 218, in <module>
conf.route = Route()
File "/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/route.py", line 37, in __init__
self.resync()
File "/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/route.py", line 45, in resync
from scapy.arch import read_routes
File "/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/arch/__init__.py", line 124, in <module>
from scapy.arch.bpf.supersocket import *  # noqa F403
File "/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/arch/bpf/supersocket.py", line 27, in <module>
from scapy.layers.l2 import Loopback
File "/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/layers/l2.py", line 17, in <module>
from scapy.ansmachine import AnsweringMachine
ImportError: cannot import name 'AnsweringMachine' from partially initialized module 'scapy.ansmachine' (most likely due to a circular import) (/Users/zhaozihao/PycharmProjects/MachineProject/venv/lib/python3.8/site-packages/scapy/ansmachine.py)
Process finished with exit code 1
你能给我一些建议或解决方案吗?谢谢。

from scapy.layers.inet import ICMP, IP

直接导入inet会导致此问题。相反,尝试导入

从scapy

。所有导入*

这将引入ICMP, IP和scapy.layers.inet

进口scapy。

,用scapy代替IP。带scapy的IP和ICMP。ICMP

相关内容

  • 没有找到相关文章

最新更新