使用 Scapy 和无线网卡扫描网络 - 出现 Network is down 错误

问题描述 投票:0回答:2

免责声明:我不能使用aircrack 我正在使用 Ubuntu(如果有帮助的话)

我有一个无线网络适配器USB设备,我正在使用它(tenda N150)来扫描网络。 我使用了一个教程,在教程中他们要求将设备置于监控模式

sudo ifconfig wlan0 down
sudo iwconfig wlan0 mode monitor

我正在运行的代码是:

from scapy.all import *
from threading import Thread
import pandas
import time
import os

# initialize the networks dataframe that will contain all access points nearby
networks = pandas.DataFrame(columns=["BSSID", "SSID", "dBm_Signal", "Channel", "Crypto"])
# set the index BSSID (MAC address of the AP)
networks.set_index("BSSID", inplace=True)

def callback(packet):
    if packet.haslayer(Dot11Beacon):
        # extract the MAC address of the network
        bssid = packet[Dot11].addr2
        # get the name of it
        ssid = packet[Dot11Elt].info.decode()
        try:
            dbm_signal = packet.dBm_AntSignal
        except:
            dbm_signal = "N/A"
        # extract network stats
        stats = packet[Dot11Beacon].network_stats()
        # get the channel of the AP
        channel = stats.get("channel")
        # get the crypto
        crypto = stats.get("crypto")
        networks.loc[bssid] = (ssid, dbm_signal, channel, crypto)


def print_all():
    while True:
        os.system("clear")
        print(networks)
        time.sleep(0.5)


def change_channel():
    ch = 1
    while True:
        os.system(f"iwconfig {interface} channel {ch}")
        # switch channel from 1 to 14 each 0.5s
        ch = ch % 14 + 1
        time.sleep(0.5)


if __name__ == "__main__":
    # interface name, check using iwconfig
    interface = "wlxc83a35c2e0bb"
    # start the thread that prints all the networks
    printer = Thread(target=print_all)
    printer.daemon = True
    printer.start()
    # start the channel changer
    channel_changer = Thread(target=change_channel)
    channel_changer.daemon = True
    channel_changer.start()
    # start sniffing
    sniff(prn=callback, iface=interface, monitor=True)

我收到的错误是:

OSError: [Errno 100] Network is down

这是

iwconfig

的输出
wlxc83a35c2e0bb  IEEE 802.11  Mode:Monitor  Tx-Power=20 dBm   
          Retry short  long limit:2   RTS thr:off   Fragment thr:off
          Power Management:off

有什么想法为什么会发生这种情况吗?

我尝试上面写的代码

python network-programming wifi scapy packet-sniffers
2个回答
0
投票

所以,问题是我忘记了:

sudo iwconfig wlan0 up
因此,界面保持关闭状态。


0
投票

我知道您此时可能已经找到解决方案,因为没有提到解决方案,所以我将其发布,这可能会帮助其他人 试试这个:

nmcli r wifi 打开

© www.soinside.com 2019 - 2024. All rights reserved.