#!/bin/bash ip=""; host=""; mac=""; create=false; quiet=false; function scan_usage { cat << EOT usage: scan [-c] [-h] [-q] [search-reg] Options -c create output, usable as create arguments -h help -q quiet, minimal output the optional regular expression is passed to egrep EOT exit; } while getopts hcq o 2>/dev/null; do case "$o" in h) scan_usage;; c) create=true;; q) quiet=true;; esac shift; done oldifs="$IFS"; IFS=" "; if [[ ! -z $1 && $1 == "help" ]]; then scan_usage; fi if [[ $create == false && $quiet == false ]]; then echo -n "scanning $_NETWORK";for l in `nmap -sP $_NETWORK | grep ^Host | awk '{print $3"|"$2} ' |\ sed -e 's/[\(\)]//g'`; do # use search pattern if there is one if [[ ! -z $1 ]]; then l=`echo $l | egrep $1`; if [[ -z $l ]]; then continue; fi fi ip=`echo "$l" | cut -d'|' -f1`; host=`echo "$l" | cut -d'|' -f2`; # | sed -e 's/'"asdfasdfasdf"'//'; host=`echo "$host" | sed -e 's/\.'$_DOMAIN'//'`; if [[ "`hostname`" != "$host" ]]; then mac=`arp $ip |grep ether| sed -e 's/.*\([0-9A-F:]\{17\}\).*/\1/'`; else mac=`ifconfig | grep $_INTERFACE | sed -e 's/.*\([0-9A-F:]\{17\}\).*/\1/'`; fi if [[ $create == false ]]; then echo -e "$ip\t$mac\t$host"; else echo -e "$host $ip $mac"; fi done IFS="$oldifs"; exit 0; if [[ ! -z $1 && $1 != "help" ]]; then echo -n ", for $1"; fi echo " ... please wait."; fi