搭建实验环境:
实验在我的server虚拟机上操作
ip为172.25.254.176
设置真机ip
设置虚拟机desktop
1、将同一局域网中能连通的主机ip写到文件中
vim /mnt/host_ip.sh
for NUM in `seq 1 1 50 `
do ping -c1 -w1 172.25.254.$NUM &> /dev/null &&{
echo 172.25.254.$NUM >> /mnt/CLIENTUSER
}
done
2、将同一局域网中能连通的主机ip写到文件中,若文件存在时询问要覆盖原文件还是备份原文件输入到新文件或者直
接跳过不操作
vim /mnt/host_ip.sh
#!/bin/sh
[ -e "/mnt/host_ip" ]&&{
echo /mnt/host_ip is exist!!
echo "[O]verwrite [B]ackup [S]kip"
read -p "What do you want action:" WORD
ACTION=`echo $WORD | tr 'a-z' 'A-Z'`
[ "$ACTION" = "O" ] && {
rm -fr /mnt/host_ip
}
[ "$ACTION" = "B" ] && {
mv /mnt/host_ip /mnt/host_ip.bak
}
[ "$ACTION" = "S" ] && {
exit 0
}
}
for NUM in `seq 1 1 20 `
do ping -c1 -w1 172.25.254.$NUM &> /dev/null &&{
echo 172.25.254.$NUM > /mnt/CLIENTUSER
}
done