1、需求:判断192.168.1.0/24网络中,当前在线的ip有哪些,并编写脚本打印出来。
(1)创建脚本
[root@localhost scripts]# vim ip_test.sh
(2)编写脚本
#!/bin/bash
##############################################################
# File Name: ip_add.sh
# Version: V1.0
# Author: Gao_XY
# Email: Gao_XY@163.com
# Organization:https://blog.youkuaiyun.com/ens33?type=blog
# Created Time : 2024-12-23 14:34:24
# Description:
##############################################################
address='192.168.1.' #定义主机位ip变量
for i in {1..254} #循环,定义网络位ip变量
do
ip=${address}$i #定义ip
if ping -c 2 -i 0.1 $ip &>/dev/null #测试能否ping通,-c ping2次,-i 间隔0.3秒。将结果放入黑洞
then

最低0.47元/天 解锁文章
371

被折叠的 条评论
为什么被折叠?



