[plug] IP Addresses

Leon Brooks leon at brooks.smileys.net
Tue Jul 11 16:54:19 WST 2000


Christopher Darby wrote:
> what can i use to find out which ip addresses are in use on my network ???

If the machines are all Unix, ping the broadcast or network address. If
you don't know that, do:

ping $(ifconfig eth0 | gawk '-F[ :]+' '/Bcast:/ { print $6 }')

If the machines are all Windows, do:

nmblookup '*'

You can turn this into a list suitable for appending to a zonefile with:

nmblookup '*' | gawk '/</ { print $1 }'

...or if you want to preformat for the zonefile...

for x in $(nmblookup '*' | gawk '/</ { print $1 }'); do
	NODE=$(echo $x | gawk -F. '{ print $4 }')
	echo "node$NODE  IN  A  $x" >>forward.zone
	echo "$NODE  IN  PTR  node$NODE" >>reverse.zone
done

...or if you want the Windows machine's own opinions of who they are
(there may be errors and/or duplicates)...

for x in $(nmblookup '*' | gawk '/</ { print $1 }'); do
	NAME=$(nmblookup -A $NODE | gawk '/<03> { print $1 }')
	NODE=$(echo $x | gawk -F. '{ print $4 }')
	if [ X$NAME = X ]; then
		NAME=node$NAME
	fi
	echo "$NAME  IN  A  $x" >>forward.zone
	echo "$NODE  IN  PTR  $NAME" >>reverse.zone
done

Here endeth the shell script demo. See you at the meeting for an NFS
demo from Ian Kent. (-:

-- 
Linux will not get in the door by simply mentioning it... it must win
by proving itself superior. We have no marketing department, our sales
department is an FTP server in North Carolina and our programming
department spans 7 continents. Am I getting through? -- Signal11 (/.)



More information about the plug mailing list