Advertising
- Something
- Thursday, April 5th, 2007 at 8:54:45am UTC
- #!/bin/bash
- # config
- _NETWORK="10.0.0.0/24" # your network/mask
- _DOMAIN="intra.wudnerlin.net" # your domain
- _INTERFACE="eth0" # your local interface
- 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";
- if [[ ! -z $1 && $1 != "help" ]]; then
- echo -n ", for $1";
- fi
- echo " ... please wait.";
- fi
- 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;
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.