Scope
I am working on a bash-script for handling repetitive tasks with putting wlan interfaces on, of, in and out monitor mode and displaying relevant information thru each step.
I started out something like this:
wx="wlan${1}"
wxm="${wx}mon"
# $wx
echo "$wx"
echo -n "stop $wxm if up....";airmon-ng stop $wxm &> /dev/null; echo " done.";
echo -n "bringing down $wx if up....";ifconfig $wx down &> /dev/null; echo " done.";
echo -n "changing mac to random....";macchanger -r $wx &> /dev/null; echo " done.";
echo "mac-adresses randomized"
echo -n "bringing up $wx....";ifconfig $wx up&> /dev/null; echo " done.";
echo -n "putting $wx in monitor mode....";airmon-ng start $wx &> /dev/null; echo " done.";
echo "$wxm successfully put in monitor mode"
wait
I tried to different ways to import available wlan-nics and with some help from a friend, ended up with this function using find
function setup_if() {
local wx="${1}"
local wxm="${wx}mon"
echo "setting up: $wx..."
run_cmd airmon-ng stop $wxm &&
run_cmd ifconfig $wx down &&
run_cmd macchanger -r $wx &&
run_cmd ifconfig $wx up &&
run_cmd airmon-ng start $wx
wait
}
for interface in $(find /sys/class/net -name 'wlan*'); do
interface=$(basename ${interface})
setup_if ${interface} || echo "FAILED: ${interface} $previous_command"
done
Where I got stuck
Now for the next step i want to print some useful information about the status of the wlans like cat /sys/class/net/wlan*/address and iwconfig |grep --regexp wlan
Finally i would like to export my operating nics to another script for capturing traffic with airodump-ng like airodump-ng -w /root/pcap/air_capture -c 1,4,6,8,11 $all_operating_wlans
Questions:
How do i make unique variables for all detected wlans, like $w1, $w2 etc. I haven't figured out how to make it thru
find /sys/class/net -name 'wlan?mon'since it is several lines of output that requires several variables.How to make those variables accessible to my other script that will capture packets.
Are there better ways to achieve the same results still in a bash-script context?
This is my first question on stackoverflow, and i'm happy to receive feedback on how my next question could be better!