Skip to content

Instantly share code, notes, and snippets.

@spacehuhn
Last active January 16, 2024 18:17
Show Gist options
  • Save spacehuhn/6f64d0c3fe3e1327b025824ffe5ecfa8 to your computer and use it in GitHub Desktop.
Save spacehuhn/6f64d0c3fe3e1327b025824ffe5ecfa8 to your computer and use it in GitHub Desktop.
little bash script to enable monitor mode

Some wireless cards support monitor mode but won't work with airmon-ng. This is a little script helps you turning the monitor mode on! (+ it also sets the channel and the tx-power)

Usage: startWlan.sh [Interface:wlan0] [Channel:1] [Txpower:30] [Bandwidth:HT20|HT40+|HT40-]

Examples:
./startWlan.sh - enables monitor mode on wlan0, sets channel to 1 and tx-power to 30dBm.
./startWlan.sh wlan1 11 33 - enables monitor mode on wlan1, sets channel to 11 and tx-power to 33dBm.
./startWlan.sh wlan0 6 - enables monitor mode on wlan0, sets channel to 6 and tx-power to 30dBm.

Script:

#!/bin/bash
# 2017 (c) Stefan Kremser
# Simple script to start monitor mode on the provided wlan interface

# color definitions (https://en.wikipedia.org/wiki/ANSI_escape_code)
RED='\033[0;31m'
YELLOW='\033[0;33;1m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'

interface=${1:-wlan0}

# check if interface exists
ifconfig $interface down
if [ $? -eq 0 ]; then
        iwconfig $interface mode monitor
        iw dev $interface set channel ${2:-1} ${4:-}
        iwconfig $interface txpower ${3:-30}
        ifconfig $interface up
        echo -e "${GREEN}Enabled monitor mode on $interface"
        exit 0
else
        echo -e "${RED}ERROR: ${YELLOW}Please provide an existing interface as parameter! ${NC}"
        echo -e "${NC}Usage: startWlan.sh [interface:wlan0] [channel:1] [txpower:30] ${NC}"
        echo -e "${NC}Tips: check with ${CYAN}ifconfig ${NC}or ${CYAN}iwconfig ${NC}which interfaces are available! ${NC}"
        exit 1
fi
@tquentin
Copy link

I suggest to initialize and reset the color definition in each echo statements (and fixed a typo):

echo -e "${RED}ERROR: ${YELLOW}Please provide an existing interface as parameter! ${NC}"
echo -e "${NC}Usage: startWlan.sh [interface:wlan0] [channel:1] [txpower:30] ${NC}"
echo -e "${NC}Tips: check with ${CYAN}ifconfig ${NC}or ${CYAN}iwconfig ${NC}which interfaces are available! ${NC}"

Remarks: the space after "!" is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment