Vim fastping.sh #!/bin/bash # Default Settings SUBNET=$1 # C Type subnet Retry=2 # retry Times Timeout=3 # timeout seconds Output=/tmp/ping.output # Output File # function Print_help function Print_help () { echo "Examples:" Echo ${0} 172.17.32 Echo ${0} 192.168.1 Unable Exit 1 } # Check the parameter If [$#-lt 1]; Then Print_help Fi # Check the network parameter ' s format Count=0 For I in $ (echo $ |sed ' s/\.//g ') Todo count=$ ((${count}+1)) Done If [${count}-ne 3]; Then Print_help Fi # Clean the output file > ${output} function pingable () { Ping-c ${retry}-W ${timeout}-Q ${subnet}.${i} &>/dev/null && echo ${i} >> ${output} } function unpingable () { Ping-c ${retry}-W ${timeout}-Q ${subnet}.${i} &>/dev/null | | Echo ${i} >> ${output} } # Get the Check type If ["$" = "unable"]; Then Status= "Unpingable" Else Status= "Pingable" Fi # Ping as Paraller mode and write output into file For i in {1..255} Todo ${status} & Done # Wait for all ping processes done Wait # Print output with better order sum=$ (wc-l ${output} |awk ' {print $} ') echo "There are\" ${sum}\ "\ ${status}\" IPs begin With\ "${subnet}.\": " Cat ${output} | Sort-t "."-k1,1n-k2,2n-k3,3n-k4,4n | Xargs-n echo "" chmod +x fastping.sh ./fastping.sh Examples: ./fastping 172.17.32 ./fastping 192.168.1 Unable Time./fastping.sh 192.168.1 There are "pingable" IPs begin with "192.168.1": 1 10 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 28 29-30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 49 50-51 52 53 54 55 56 57 59 60 61 62 63 64 65 66 67 68 69 70 71-72 73 74 75 76 77 78 80 81 83 84 85 86 87 88 89 90 91 92 93-94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 112 113 114 115 116-117 118 119 120 121 122 123 124 125 126 127 128 133 134 135 136 137 138 139 140-141 142 143 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165-166 170 254 Real 0m3.201s User 0m0.135s SYS 0m0.495s |