Skip to content

Instantly share code, notes, and snippets.

@rdbox
Forked from spacehuhn/startwlan.md
Created April 26, 2018 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdbox/de3f2909c87f6a3cba82bc91a7def57f to your computer and use it in GitHub Desktop.
Save rdbox/de3f2909c87f6a3cba82bc91a7def57f 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!"
        echo -e "${NC}Usage: startWlan.sh [interface:wlan0] [channel:1] [txpower:30]"
        echo -e "${NC}Tipp: check with ${CYAN}ifconfig ${NC}or ${CYAN}iwconfig ${NC}which interfaces are available!"
        exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment