工作环境:Red Hat Enterprise Linux Server release 6.5 (Santiago) 、 bash

#!/bin/bash
#
nmap -n -sP 10.0.0.1-254|grep "10.0.0"|awk '{print $5}' >ceshi.txt

a=(`cat ceshi.txt |tr "\n" " "`)

echo "${a[@]}"


注释: -n  --- 不进行主机解析

       -P  --- 执行ping的用法


或者

#!/bin/bash
#扫描局域网内存活的主机
nmap -n -sT -p22 10.0.0.1-254 |egrep -o "\<10.0.0.([1-9]|[2-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\>"|sort -n >suv1_ip

nmap -n -sT -p22 10.0.10.1-254 |egrep -o "\<10.0.10.([1-9]|[2-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\>"|sort -n >suv2_ip


注释: -T  ---- 指定TCP扫描

          -p  ----- 指定端口号

严谨点的话,需要在10.0.10之间的“.”加入转义符"\",第2,3,4个字段匹配在0-255,0-255,1-254