-2

因此,我编写了一个 shell 脚本来让人们离开我的 wifi,但我无法让它正常工作。主要问题是,当我执行 bash -c "$com" 时,它没有像应有的那样设置变量。任何帮助,将不胜感激。

echo "You must be connected to the network that you wish to kick the devices off"
gw=`route -n|grep ^0.0.0.0|cut -d' ' -f 10`
sudo nmap -sP $gw-254
long='read -p Enter_the_DEVICE_Bssid'
a=1
end=';'
oend='&'
outside='"'
thesudo='sudo'
num=1
deff='aireplay-ng -0 $number -a $bssid mon0 --ignore-negative-one -c'
read -p "How many devices do you want to kick: " ammount
counter=0
while [ $counter -lt $ammount ];
do
    b=device
    d1=$b$a

    if [ $counter2 -gt $ammount ]
    then
        com="$com $long $outside$d1$outside" 
        counter=$(($counter +1))
    else
        com="$com $long $outside$d1$outside $end"
    fi


    comfin="$comfin $thesudo $deff $d1 $oend"
    a=$(($a +1))
    counter=$(($counter +1))
    counter2=$(($counter +2))
done
vev="echo done"
comfin="$comfin $vev"
echo $com
bash -c "$com"
#Why does it not set the variables like it should?
echo $device1
echo $device2
echo $device3
#see it dosent say the variables when it is run.
sudo ifconfig wlan0 down
sudo macchanger -m 00:11:22:33:44:55 wlan0
sudo ifconfig wlan0 up
sudo airmon-ng start wlan0
sudo ifconfig mon0 down
sudo macchanger -m 00:11:22:33:44:55 mon0
sudo ifconfig mon0 up

#make sure you dont run it from the file, but from terminal so you can press ctrl z to stop the airodump
echo "make sure you dont run it from the file, but from terminal so you can press ctrl z to stop the airodump"
sleep 2
sudo airodump-ng mon0

read -p "Enter the NETWORK Bssid:" bssid
echo "Ok, its $bssid"

read -p "Do you want to single kick(1) or continuously kick(0)" number
echo "Ok, its $number"

sudo $comfin

sudo ipconfig stop mon0
4

1 回答 1

1

bash -c "command"在新bash进程中运行命令。该过程中的变量设置不会对原始过程产生任何影响。如果要在原始进程的环境中执行命令,请使用eval

eval "$com"

不过,您可能应该重新考虑您的整个方法。动态分配变量通常是设计不正确的标志。您应该使用数组,而不是使用单独的变量device1, device2, 。device3

read -p 'Enter the device' dev
device[$counter]=$dev
于 2015-01-31T00:03:26.800 回答