[英]How to ping several hosts at the same time (bash) linux
ip="192.168.129."
function addToList(){
list="$list $1"
}
addToList $1
for i in $ip{$list}
do
ping -c 1 $ip$1 > /dev/null
echo "Ping Status of $ip$1 : Success" ||
echo "Ping Status of $ip$1 : Failed"
done
如何同时 ping 多台主机并将其显示在列表中,哪个 ip 地址是 up 或 down?
一种方法是使用更强大的ping
工具,如fping 。
另一种方法是在后台运行 ping:
for ip in $*; do
if [[ "$ip" =~ "^[0-9]+$" ]]; then
ip="192.168.129.$ip"
fi
(
ping -c 1 $ip > /dev/null
if [ $? -eq 0 ]; then
echo "node $ip is up"
else
echo "node $ip is down"
fi
)&
done
(...)&
在后台运行脚本。
这是我在阅读类似帖子后编写的脚本。
https://bitbucket.org/kurtjensen/nettest/src/master/
它可以使用多个文本文件作为可能的配置,并且配置文件让您有机会更详细地命名 IP 地址。 示例配置文件是
所以我可以在家里运行脚本,然后在提示符下按回车键或输入类似“momdad”的内容来切换到不同网络的不同配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.