查找某一网段内的所有主机的脚本,此脚本在主机所在网段内扫描,并把得到的主机名记录到文件中,有点类似局域网查看工具(LanSee)
例如主机所在网段是 192.168.33.0
一、脚本代码如下:
查找某一网段内的所有主机的脚本_休闲
查找某一网段内的所有主机的脚本_职场_02
 
二、脚本运行状态如下:
查找某一网段内的所有主机的脚本_shell_03
(点击此图可放大)

参考脚本:

#set -x
cat /dev/null > record.txt
nmblookup \*|grep '<00>'|awk '{print $1}' >record.txt
#ping -c 2 -b 192.168.33.255|grep 64|awk '{print $4}'|sed -e 's/://g'>record.txt
. /etc/bashrc
NO=`cat record.txt|wc -l`
cat /dev/null > result
cat /dev/null > netbios_name
color black_green
cat <<EOF
################################
You will try $NO addresses
################################
EOF
#color black_white
echo "press return to continue"
read test
while read ip_addr
do
echo "We will try to test:$ip_addr"
###################################
nmblookup -A $ip_addr |grep  '<00> -         [B|M]'|awk '{print $1}' >>netbios_name
smbclient -I $ip_addr -M `nmblookup -A $ip_addr |grep  '<00> -         [B|M]'|awk '{print $1}'` << EOF
###############
[=^T^=]
###############
EOF
done < record.txt