19.1.4企业Shell面试题4:扫描网络内存活主机案例

写一个Shell脚本,判断10.0.0.0/24网络里,当前在线的IP有哪些?

 

[root@st153 tools]# cat check_user.sh 
#!/bin/bash
bb=0
for i  in 10.0.0.{1..254}
do
    aa=$(ping $i -c 2|awk 'NR==6{print $4}')
    if [ ${aa} -gt 0 ]
    then
        echo "${i} is online"
        ((bb+=1))
        fi            

done

echo $bb

 

方法二:

 

[root@cache01 yum.repos.d]# nmap 10.0.0.*|grep 10.0.0.*|awk '{print $NF}'
10.0.0.1
10.0.0.8
10.0.0.51
10.0.0.61
10.0.0.64
10.0.0.21

 

相关文章:

  • 2021-05-24
  • 2021-07-25
  • 2021-12-23
  • 2022-12-23
  • 2021-05-15
  • 2021-09-18
  • 2021-06-08
  • 2021-12-28
猜你喜欢
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案