#!/usr/bin/env bash

# Usage:       ./airodump-script
#                or
#              bash airodump-script
# Description: Performs all needed steps to gather WLAN endpoints and
#                stores the results in an csv file with utc date in file name.
# Author:      Patrick Neumann (patrick@neumannsland.de)
# Platform:    Kali Linux (tested: 2018.2)
# Version:     1.0
# Date:        24.08.2018
# Link:
#   https://vcs.neumannsland.de/casualscripter/shell-scripting/src/branch/master/kali/airodump-script
# License:     GPL3
# Warranty:    This program is distributed WITHOUT ANY WARRANTY

# check for root
if [[ 0 -ne "$( /usr/bin/id --user )" ]] ; then
  printf "you need to be root - EXIT!\n"
  exit 2
fi

# config
DESTINATION="/root/Documents/airodump-ng-$( date -u +%Y%m%d%H%M%S )"

# select wlan option
printf "Please select a WLAN nic:\n"
select NIC in $( ls /sys/class/net | grep -F wlan ) ; do
  if [ -n "${NIC}" ] ; then break ; fi
done

# deconfigure the network
systemctl stop NetworkManager.service
pkill dhclient &> /dev/null

# bring the wlan option into monitoring mode
airmon-ng start "${NIC}"

# gather as much information about WLANs as possible
#   (let run it "some" minutes end exit it with <ctrl>+<c>.)
airodump-ng --band abg --write "${DESTINATION}" --output-format csv "${NIC}"mon

# stop monitoring mode
airmon-ng stop "${NIC}"mon

# reconfigure the network
systemctl start NetworkManager.service

exit 0