我决定编写一个用于基本 nmap 扫描的 shell 脚本,因此我这样做了:
#!/bin/bash
sudo apt-get install nmap
printf "enter the name of site to do basic scan on >>>"
read NAME
nmap $NAME
echo "Do you wish to do Software Version scan?"
select yn in "Yes" "No"; do
case $yn in
Yes ) goto 17; break;;
No ) exit;;
nmap $NAME -sV
echo "Do you wish to do OS scan?"
select yn in "Yes" "No"; do
case $yn in
Yes ) goto 25; break;;
No ) exit;;
nmap $NAME -O
但输出是:
Nmap done: 1 IP address (1 host up) scanned in 109.97 seconds
Do you wish to do Software Version scan?
./nmap-basic.sh: line 17: syntax error near unexpected token `$NAME'
./nmap-basic.sh: line 17: `nmap $NAME -sV'
有什么解决办法吗?
答案1
case
在 bash 中应该以 结尾esac
,select
应该以 结尾done
。我在您的脚本中没有看到这些关键字。
select NAME [in WORDS ... ;] do COMMANDS; done
case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac
答案2
你的 shell 脚本有很多问题,我为你重写了它。
#!/bin/bash
echo -en "Enter name of website ?"
read name
echo -e "\e[93mScanning...\e[0m"
nmap $name
# software Scan
echo "############################################"
echo "Do you wish to do Software Version scan?"
read ans
if [ "$ans" = "yes" ] || [ "$ans" = "YES" ]
then
echo "############################################"
echo -e "\e[91m Software Scanning...\e[0m"
nmap -sV $name
fi
## OS Scan
echo "Do you wish to do OS scan?"
read ans
if [ "$ans" = "yes" ] || [ "$ans" = "YES" ]
then
echo -e "\e[92m OS Scanning...\e[0m"
sudo nmap -O $name
fi
exit 0
实际上你不需要 select 命令,因为在“否”的情况下你没有任何工作要做,并且你可以在循环中使用 break|continue,而不是在 case 语句中使用。我添加了一些颜色让它变得漂亮。玩得开心兄弟