当前位置:网站首页>Shell script case branch statement, pick the max address of anonymous login FTP
Shell script case branch statement, pick the max address of anonymous login FTP
2022-07-19 02:47:00 【For whom do the stars change】
1、 Sentence structure
case A variable's value in
Model a ) Command sequence 1
;;
Model 2 ) Command sequence 2
;;
......
*)
esac
2、case Statement application example
(1) Check the character type entered by the user
Prompt the user to enter a character from the keyboard , adopt case Statement to determine whether the character is a letter 、 Numbers or other control characters
vim a.sh
#!/bin/bash
read -p " Please enter a character , And press Enter Key confirmation :" KEY
case "$KEY" in
[a-z] | [A-Z]) ( Match any letter )
echo " You entered the letters ."
;;
[0-9]) ( Match any number )
echo " You have entered a number ."
;;
*) ( The default mode , Match any character )
echo " You have entered a space 、 Function keys or other control characters ."
esac
chmod +x a.sh
./a.sh (2) System scripting service
By position variable $1 designated start, stop, restart, status Control parameter , Respectively used to start 、 stop it 、 restart sleep process
vim fuwu.sh
#!/bin/bash
case "$1" in
start)
echo -n " Starting sleep service ..."
if sleep 9000 &
then
echo "OK"
fi
;;
stop)
echo -n " Stopping sleep service ..."
pkill "sleep" &> /dev/null
echo "OK"
;;
status)
if pgrep "sleep" &> /dev/null
then
echo "sleep Service started ."
else
echo "sleep The service has stopped ."
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo " usage :$0 {start|stop|status|restart}"
esac
chmod +x fuwu.sh
./fuwu.sh start
./fuwu.sh stop
./fuwu.sh status
./fuwu.sh restart(3) adopt arping Command send ARP request , Record according to the feedback results MAC Address .( Need one vsftp The server )
Add network segment address ( Such as 192.168.1.) Assign a value to a variable NADD, As the prefix of the detection address .
Use while Loop statement , Repeatedly detect the target and record MAC Address , Host address from 1-254.
vim getarp.sh
#!/bin/bash
# 1. Define the network segment address 、MAC List file
NADD="192.168.1."
FILE="/etc/ethers"
# 2. send out ARP request , And record the feedback results
[ -f $FILE ] && /bin/cp -f $FILE $FILE.old ( Back up the original file )
HADD=1 ( Define the starting scanning address )
while [ $HADD -lt 30 ]
do
ping -c 2 -i 0.2 -W 3 ${NADD}${HADD} &> /dev/null
if [ $? -eq 0 ]
then
arp -n | grep ${NADD}${HADD} | awk '{print $1,$3}' >> $FILE
fi
let HADD++
done
chmod +x getarp.sh
./getarp.sh
cat /etc/ethers
(4) Check whether a host is anonymous FTP service
wget Download tools to visit FTP The way of root directory , If you can successfully list , Is considered anonymous FTP Enabled , Otherwise, it is regarded as closed
vim scanhost.sh
#!/bin/bash
TARGET=$(awk '{print $1}' /etc/ethers)
echo " The following hosts have been opened for anonymity FTP service :"
for IP in $TARGET
do
wget ftp://$IP/ &> /dev/null
if [ $? -eq 0 ]
then
echo $IP
rm -rf index.html ( Delete the temporary file generated by the test )
fi
done
chmod +x scanhost.sh
./scanhost.sh边栏推荐
- Dynamic programming problem - Small Soldiers rush forward
- Image quality evaluation indicators: SNR, PSNR, MSE and SSIM
- C语言回调函数 & sprinf 实际应用一例
- Tree array and St table
- 让我们了解awk~
- Usage instructions for MDK keil/arm printf
- Dynamic programming - 01 knapsack problem
- shell脚本接收和返回参数
- YUM仓库服务与PXE自动部署系统
- Sword finger offer 48 The longest substring without repeated characters
猜你喜欢
随机推荐
HCIA_RIP实验
RIP综合实验
module_init函数底层原理
Image quality evaluation indicators: SNR, PSNR, MSE and SSIM
An example of C language callback function & sprinf practical application
DNS domain name resolution
Leetcode buckle classic topic - 82 Maximum rectangle in column chart
expect免交互
通过Xshell7使用rz,sz命令上传下载文件
rsync远程同步(增量备份)
Tree array and St table
regular expression
Echo -e usage
Use of sqlmap
Shell脚本变量、脚本编写和执行(部署Apache与远程备份MySQL数据库)
Response assertion of JMeter interface test
Interview: the difference between interface and abstract class - concise summary
[unity Editor Extension] displays the memory size of all files in the resource directory
Understanding: what is interface and the concept of interface
Longest ascending subsequence - Optimization









