#!/bin/bash # Raspberry Pi 5 WiFi Monitor Mode Setup Script # Run this script with sudo on your Raspberry Pi set -e # Configuration WIFI_INTERFACE="wlan0" # Change if your interface is different MONITOR_INTERFACE="mon0" # Monitor mode interface name CHANNEL="${1:-11}" # Default to channel 11, or pass as argument: ./rpi_monitor_setup.sh 36 echo "=== Raspberry Pi 5 WiFi Monitor Mode Setup ===" echo "Interface: $WIFI_INTERFACE" echo "Monitor interface: $MONITOR_INTERFACE" echo "Channel: $CHANNEL" echo "" # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Please run as root (use sudo)" exit 1 fi # Check if interface exists if ! ip link show "$WIFI_INTERFACE" &>/dev/null; then echo "Error: Interface $WIFI_INTERFACE not found" echo "Available interfaces:" ip link show | grep -E "^[0-9]+:" | awk '{print $2}' | sed 's/://' exit 1 fi # Check if monitor interface already exists if ip link show "$MONITOR_INTERFACE" &>/dev/null; then echo "Monitor interface $MONITOR_INTERFACE already exists. Removing..." iw dev "$MONITOR_INTERFACE" del fi # Bring down the interface echo "Bringing down $WIFI_INTERFACE..." ip link set "$WIFI_INTERFACE" down # Set monitor mode echo "Setting $WIFI_INTERFACE to monitor mode..." iw dev "$WIFI_INTERFACE" set type monitor # Bring up the monitor interface echo "Bringing up monitor interface..." ip link set "$WIFI_INTERFACE" up # Set channel echo "Setting channel to $CHANNEL..." iw dev "$WIFI_INTERFACE" set channel "$CHANNEL" # Verify monitor mode echo "" echo "=== Verification ===" iw dev "$WIFI_INTERFACE" info echo "" echo "=== Monitor mode is now active! ===" echo "Interface: $WIFI_INTERFACE" echo "Channel: $CHANNEL" echo "" echo "To capture packets, you can use:" echo " sudo tcpdump -i $WIFI_INTERFACE -n" echo " sudo tcpdump -i $WIFI_INTERFACE -w capture.pcap" echo " sudo wireshark -i $WIFI_INTERFACE" echo "" echo "To stop monitor mode and restore normal WiFi:" echo " sudo ip link set $WIFI_INTERFACE down" echo " sudo iw dev $WIFI_INTERFACE set type managed" echo " sudo ip link set $WIFI_INTERFACE up" echo " # Then reconnect to your network"