检查某个网段存活的主机_shell脚本
工作环境:Red Hat Enterprise Linux Server> #!/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 "\"|sort -n >suv1_ip
nmap -n -sT -p22 10.0.10.1-254 |egrep -o "\"|sort -n >suv2_ip
注释: -T---- 指定TCP扫描
-p----- 指定端口号
严谨点的话,需要在10.0.10之间的“.”加入转义符"\",第2,3,4个字段匹配在0-255,0-255,1-254
页:
[1]