首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >scapy.error.Scapy_Exception:无法附加BPF过滤器

scapy.error.Scapy_Exception:无法附加BPF过滤器
EN

Stack Overflow用户
提问于 2021-12-31 00:55:24
回答 2查看 767关注 0票数 1

我在youtube上找到了一个用python写的WiFi扫描仪。https://www.youtube.com/watch?v=DFTwB2nAexs直接GitHub脚本链接:arp.py

但是我对BPF过滤器有一个问题:"scapy.error.Scapy_Exception:无法附加BPF过滤器!!“

脚本

代码语言:javascript
复制
#!/usr/bin/env python3
# Import scapy
import scapy.all as scapy

# We need to create regular expressions to ensure that the input is correctly formatted.
import re

# Basic user interface header
print(
    r"""______            _     _  ______                 _           _ 
|  _  \          (_)   | | | ___ \               | |         | |
| | | |__ ___   ___  __| | | |_/ / ___  _ __ ___ | |__   __ _| |
| | | / _` \ \ / / |/ _` | | ___ \/ _ \| '_ ` _ \| '_ \ / _` | |
| |/ / (_| |\ V /| | (_| | | |_/ / (_) | | | | | | |_) | (_| | |
|___/ \__,_| \_/ |_|\__,_| \____/ \___/|_| |_| |_|_.__/ \__,_|_|"""
)
print("\n****************************************************************")
print("\n* Copyright of David Bombal, 2021                              *")
print("\n* https://www.davidbombal.com                                  *")
print("\n* https://www.youtube.com/davidbombal                          *")
print("\n****************************************************************")

# Regular Expression Pattern to recognise IPv4 addresses.
ip_add_range_pattern = re.compile("^(?:[0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]*$")

# Get the address range to ARP
while True:
    ip_add_range_entered = input(
        "\nPlease enter the ip address and range that you want to send the ARP request to (ex 192.168.1.0/24): "
    )
    if ip_add_range_pattern.search(ip_add_range_entered):
        print(f"{ip_add_range_entered} is a valid ip address range")
        break


# Try ARPing the ip address range supplied by the user.
# The arping() method in scapy creates a pakcet with an ARP message
# and sends it to the broadcast mac address ff:ff:ff:ff:ff:ff.
# If a valid ip address range was supplied the program will return
# the list of all results.
arp_result = scapy.arping(ip_add_range_entered)

输出

代码语言:javascript
复制
Please enter the ip address and range that you want to send the ARP request to (ex 192.168.1.0/24): 192.168.1.0/24
192.168.1.0/24 is a valid ip address range
Traceback (most recent call last):
  File "/Users/belgra/Development/WiFi Scanner/lan_scan_arp.py", line 41, in <module>
    arp_result = scapy.arping(ip_add_range_entered)
  File "/opt/homebrew/lib/python3.10/site-packages/scapy/layers/l2.py", line 734, in arping
    ans, unans = srp(
  File "/opt/homebrew/lib/python3.10/site-packages/scapy/sendrecv.py", line 675, in srp
    s = iface.l2socket()(promisc=promisc, iface=iface,
  File "/opt/homebrew/lib/python3.10/site-packages/scapy/arch/bpf/supersocket.py", line 254, in __init__
    super(L2bpfListenSocket, self).__init__(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/scapy/arch/bpf/supersocket.py", line 119, in __init__
    attach_filter(self.ins, filter, self.iface)
  File "/opt/homebrew/lib/python3.10/site-packages/scapy/arch/bpf/core.py", line 155, in attach_filter
    raise Scapy_Exception("Can't attach the BPF filter !")
scapy.error.Scapy_Exception: Can't attach the BPF filter !
/Users/belgra/Development/WiFi Scanner ❯                                  

我安装了替罪羊2.4.5,并通过Python3.10.1在M1 Mac上运行这段代码。

有什么想法吗?

EN

回答 2

Stack Overflow用户

发布于 2022-03-31 21:48:25

我能够通过安装Scapy在安装文档中提到的可选libpcap库来解决这个问题。

  1. 在终端中运行brew update
  2. 在终端中运行brew install libpcap
  3. 在您的终端中使用scapy运行Scapy
  4. 在Scapy中运行conf.use_pcap = True

下面是包含更多信息的文档的链接

作为参考,我正在使用python3.8.12运行M1 MacBook Air (macOS蒙特雷v12.1)。

票数 2
EN

Stack Overflow用户

发布于 2022-05-02 12:22:12

我在一个M1 MacBook上得到了同样的错误,我按照@RBPEDIIIAL的建议,通过安装和配置libpcap来解决这个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70538069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档