将接口卡设置为监控模式

时间:2018-02-17 21:14:20

标签: shell

为什么这段代码不起作用,在第8行和第12行中给出了错误

  

./ monitor.sh:8行:[iface:找不到命令   ./monitor.sh:第12行:[iface:命令未找到

iface应该是变量,这里是代码

#!/bin/bash

ip link set wlan1

echo Please enter your wifi interface of choice
read iface

if [iface == wlan1]
then
   iw wlan1 set monitor control
   echo wlan1 is set in monitor mode
elif [iface == wlan0]
then
   iw wlan0 set monitor control
   echo wlan0 is now set in monitor mode
else
   echo No card was put into monitor mode, try again
fi

2 个答案:

答案 0 :(得分:1)

在第6行读完后使用$ iface 如果格式不正确

应该是:

if [ $iface == "wlan1" ]

答案 1 :(得分:0)

if [iface == wlan1]应为if [ $iface == wlan1 ]。空间和印记都是必需的。