在Raspberrypi(Systemd)中重新启动时使用scapy sniff

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

TL; DR:为什么从systemd重新引导时Scapy的嗅探不运行?

我在RPI3上运行以下代码,专门查找网络请求。这使用内置的ETH0 wifi:

monitorConnections.py

def arp_detect(pkt):

    print("Starting ARP detect")
    logging.debug('Starting ARP detect')

    if pkt.haslayer(ARP):


        if pkt[ARP].op == 1: #network request
            PHONE_name = "Unknown"
            PHONE_mac_address = ""

            if pkt[ARP].hwsrc in known_devices.keys():
                print ("Known Phone Detected")
                logging.debug('Known Phone Detected')

                # Grab name and mac address
                PHONE_mac_address = pkt[ARP].hwsrc
                PHONE_name = known_devices[PHONE_mac_address]

                print ('Hello ' + PHONE_name)
                logging.debug('Hello ' + PHONE_name)

            else:
                # Grab mac address, log these locally

                print ("Unknown Phone Detected")
                logging.debug('Unknown Phone Detected')

                PHONE_mac_address = pkt[ARP].hwsrc

        print (pkt[ARP].hwsrc)

print("Start!")
print (sniff(prn=arp_detect, filter="arp", store=0))

当我通过命令运行时

python2 monitorConnections.py

此程序按设计运行,但是我一直试图将其放在守护程序中,意识到必须在建立Internet连接后运行它。我的服务具有以下设置:

MonitorConnections.service

[Unit]
Description=Monitor Connections
Wants=network-online.target
After=network.target network-online.target sys-subsystem-net-devices-wlan0.device sys-subsystem-net-devices-eth0.device

[Service]
Type=simple
ExecStart=/usr/bin/python2 -u monitorConnections.py
ExecStop=pkill -9 /usr/bin/autossh
WorkingDirectory=/home/pi/Shared/MonitorPhones
Restart=always
User=root

StandardOutput=console
StandardError=console

[Install]
WantedBy=multi-user.target

为了找到需要我的脚本才能运行的服务,我运行了此命令:

systemctl list-units --no-pager

要在“之后”下找到以下要添加到我的服务中的服务-这些与以太网相对应服务(我想像!)

sys-subsystem-net-devices-wlan0.device
sys-subsystem-net-devices-eth0.device

据我所知,这正在成功运行。当我保存所有内容并运行以下命令:

sudo systemctl daemon-reload
sudo systemctl restart monitorConnections

这很好地启动了脚本。然后,我将脚本设置为在重新启动时运行,如下所示:

sudo systemctl enable monitorConnections

然后重新启动,我可以看到它运行了打印语句“ Start”,但是随后似乎没有在'sniff'命令中运行任何内容,但是在运行时

sudo systemctl -l status monitorConnections

我可以看到该脚本处于活动状态-因此它没有出错!

我的问题:为什么scapy的嗅探似乎在重新启动时没有运行?我错过了什么吗

老实说,我对什么地方出了问题,对此有任何帮助,将不胜感激!

python raspberry-pi scapy systemd
1个回答
0
投票

RPI3的wifi驱动程序没有监视模式。经过数周的调试,这已成为问题所在。我希望这对其他人有帮助。

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