Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Networking

Simple Network Discovery

Submitted by on August 21, 2013 – 11:38 am

The bash script below will scan the specified IP range and use dig and nmap to try to determine the fully-qualified domain name, type and the operating environment of any device that responds to network pings. You can add the “–osscan-guess” option to the nmap command to enable the “guessing” mode for the OS type.

#!/bin/bash
echo -e "IPtFQDNtDevice TypetOS TypetOS Details"
for i in `echo 192.168.{1.255}.{1..255}`
do
	if [ `ping -w 1 -c 1 $i >/dev/null 2>&1 ; echo $?` -eq 0 ]
	then
		echo -ne "${i}t"
		node=$(dig +short -x ${i} | head -1 | sed -e 's/.$//g' 2>/dev/null)
		if [ -z ${node} ]
		then
			node=unknown
		fi
		echo -ne "${node}t"
		nmap -O -v ${i} | egrep -i "^Device type:|^Running:|^OS Details:|^Aggressive OS" | 
		awk -F':' '{print $2}' | sed -e 's/^ //g' -e 's/(.[0-9]%)//g' -e 's/|/, /g' | while read line
		do
			echo -ne "${line}t"
		done
		echo ""
	fi
done

 

Print Friendly, PDF & Email

Leave a Reply