zoukankan      html  css  js  c++  java
  • 《通过脚本查看哪些ip被占用》shell笔记

    改脚本查看哪些ip被占用。

    #!/bin/bash

    for i in {1..10}   //赋予i变量1-10

    do   //干什么

    ping -c1 -w1 192.168.7.$i &> /dev/null   //ping 192.168.7.网段 每个ip1次 显示1行全输出到无底洞

    if [ $? -eq 0 ]; //返回值是否为0

    then   //如果返回值为0则做下面的输出

    echo station$i is up!

    else   //否则

    echo station$i is down!  //输出这步

    fi   done 

    赋予该脚本可执行权限: chmod +x ipadd.sh  

    执行该脚本:

    [root@localhost shellscripts]# ipadd.sh

    station1 is up!

    station2 is down!

    station3 is up!

    station4 is down!

    station5 is down!

    station6 is down!

    station7 is down!

    station8 is down!

    station9 is down!

    station10 is down!

    ===========================

    [root@localhost shellscripts]# ping 192.168.7.3

    PING 192.168.7.3 (192.168.7.3) 56(84) bytes of data. 64 bytes from 192.168.7.3:

    icmp_seq=1 ttl=64 time=0.043 ms 64 bytes from 192.168.7.3:

    icmp_seq=2 ttl=64 time=0.040 ms ^C --- 192.168.7.3

    ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1791ms rtt min/avg/max/mdev = 0.040/0.041/0.043/0.006 ms

    [root@localhost shellscripts]# echo $?   //ping通返回值为0

    0 ==============================

    [root@localhost shellscripts]# ping 192.168.7.4

    PING 192.168.7.4 (192.168.7.4) 56(84) bytes of data.

    From 192.168.7.3 icmp_seq=1 Destination Host Unreachable From 192.168.7.3

    icmp_seq=2 Destination Host Unreachable From 192.168.7.3

    icmp_seq=3 Destination Host Unreachable ^C --- 192.168.7.4

    ping statistics --- 5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4084ms pipe 3

    [root@localhost shellscripts]# echo $? 1     //ping不通返回值不为0

  • 相关阅读:
    隧道适配器,本地连接过多的解决办法
    C# 遍历HashTable
    sql2005 数据库转为sql 2000数据库的步骤
    自动扫描IP代理地址和自动切换IP的软件
    JS实现网页图片延迟加载[随滚动条渐显]
    批量修改hosts
    C#.NET获取当前月份最大天数
    如何让js调用不影响页面的加载速度?
    在sql中如何替换去掉回车符?
    Linq(01)对Linq的疑问及学习路径
  • 原文地址:https://www.cnblogs.com/linux-super-meng/p/3753876.html
Copyright © 2011-2022 走看看