Title: Write a shell script that uses ping to determine whether the host in the specified IP or IP side is alive.
Accept only the specified IP format input and IP segment input (for example: 192.168.2.88 or 192.168.2.) Note that there is a point behind the Write IP segment ... Script Simple ... Reader, please. Code on:
#!/bin/bash read-p "Please input IP: (192.168.0.22) or (192.168.0.)" Ip test= ' echo $Ip |grep ' \<[0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\}\$ "' test1= ' echo $Ip |grep" \<[0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\}\.\$ "' #echo" a IP is: $Test "#echo" ip.is $Test 1 "If [[z $Test &&-z $Test 1]];then Echo]
Input error! "
Exit 1 elif [[-N $Test]];then for i in ' SEQ 1 4 ' Do cut= ' echo $Test |cut-d. '-f$i '
If [$i-eq 1];then if [$Cut-gt 223-o $Cut-lt 1];then
echo "Input $Test---->> $Cut Invalid" Exit 2 fi else if [$Cut-gt 254];then echo "Input $Test----&G
T;> $Cut Invalid "Exit 2 fi fi done If Ping-c 2-W 1 $Test &>/dev/null then echo "Have $Test" Else echo "No $Test" fi else for I-in ' SEQ 1-3 ' do cut= ' echo $Test 1|cut-d "."
-f$i ' If [$i-eq 1];then if [$Cut-gt 223-o $Cut-lt 1];then
echo "input $Test 1---->> $Cut invalid" Exit 2 Fi else if [$Cut-gt 254];then echo "input $
Test1---->> $Cut Invalid "Exit 2 fi fi
Done Declare-i Num declare-i Fail num=0 fail=0 For i in ' seq 1 ' do if ping-c 1-w 1 ${test1} $i &>/dev
/null; then. echo "Have ${test1} $i" num=$ ((num+1)) Else
fail=$ ((fail+1)) echo "No ${test1} $i" fi
Done Echo "Host online have $Num." echo "Host no online have $Fail."
The last for the loop, I too much, only wrote 10 values, interested in the brothers, their own changes to the 1 10 seq to 1 254 can ... There is a Class B class C network, due to my lack of knowledge of the network, so the value of the judgement, estimated quite incorrect, you will understand it ....