This document describes bettercap_arp_spoofing_script_auto.py — an automated Python controller that manages a Bettercap subprocess, discovers hosts, lets the operator select targets interactively, and then configures ARP spoofing and packet sniffing.
The README below focuses on the script's actual behavior and implementation details (parsing logic, subprocess management, and interactive workflow).
- Starts Bettercap (via
sudo bettercap -iface <iface>) and manages its stdin/stdout - Threads stdout reading to stream live output while keeping the CLI responsive
- Strips ANSI escape codes from Bettercap output before parsing or display
- Parses discovered hosts from both log-style messages and the formatted
net.showtable - Interactive selection of one or more targets by index
- Supports setting
arp.spoof.fullduplexandarp.spoof.targetsand enablesnet.sniff - Graceful termination and basic error handling
- Validates that a network interface argument was provided on the command line.
- Launches Bettercap using
sudo bettercap -iface <iface>viasubprocess.Popen.- If
bettercapis not found the script prints an error and exits.
- If
- Starts a background thread that continuously reads Bettercap's stdout and appends each line to an in-memory buffer while also printing it live to the console.
- Sends
net.probe onto Bettercap to start host discovery; the operator can press Enter when they want to stop discovery. - Sends
net.probe offandnet.showto obtain a summary of discovered hosts, waits briefly, and then stops the background reader. - Parses the captured output using two complementary parsers:
parse_devices_log— searches log-style lines for endpoint detection messages and extracts IP, MAC, name and vendor (it strips ANSI codes before regex matching).parse_devices_table— parses the box-drawnnet.showtable (rows beginning with│) to extract IP, MAC, name and vendor columns (also strips ANSI codes).
- De-duplicates combined results and prints a numbered list of discovered devices.
- Prompts the operator to select one or more devices by index (for example
0or1,3) and to choose whether to enable full-duplex spoofing (y/n). - Sends a single Bettercap command that sets
arp.spoof.fullduplex,arp.spoof.targets, enablesarp.spoofandnet.sniff. - Streams Bettercap output until the operator hits Ctrl+C; on KeyboardInterrupt the script attempts to terminate the Bettercap subprocess.
- The script strips ANSI escape sequences from Bettercap output before parsing (this avoids parsing errors caused by color codes).
- Two parsing strategies are used because Bettercap output format can vary across versions: both log entries and a rendered table are supported.
- The script uses
sudoto start Bettercap in thestart_bettercapfunction. If you prefer not to run the script with sudo, adjust invocation accordingly.
Run the script with Python 3 and pass the network interface name (use sudo if required by your system):
sudo python3 python-scripts/bettercap_arp_spoofing_script_auto.py <network_interface>Example:
sudo python3 python-scripts/bettercap_arp_spoofing_script_auto.py wlan0On start the script will show Bettercap's live output. Follow the prompts to review discovered hosts and select targets.
- Python 3.x (no third-party packages required)
- Bettercap installed and available on the PATH
- Sudo/privileged access for network interface operations
- Parsing is best-effort — different Bettercap versions or localized output may require tweaks to the regex or table parsing logic.
- The script currently terminates Bettercap on KeyboardInterrupt. A safer cleanup sequence would explicitly disable
arp.spoofbefore exit. - Consider adding an explicit check for
sudoavailability and clearer instructions when running without elevated privileges. - Add an option to save discovery results and sniffed packets to a timestamped log or pcap file.
- Optionally implement a non-interactive mode that accepts targets and fullduplex as CLI flags for automation.
This tool performs ARP spoofing and packet capture. Only run it in environments where you have explicit authorization (lab networks, VMs, or systems you own). Unauthorized use is illegal and unethical.