All pastes #425149 Raw Edit

Something

public shellscript v1 · immutable
#425149 ·published 2007-04-05 08:54 UTC
rendered paste body
#!/bin/bash# config_NETWORK="10.0.0.0/24" # your network/mask_DOMAIN="intra.wudnerlin.net" # your domain_INTERFACE="eth0" # your local interfaceip=""; host=""; mac=""; create=false; quiet=false;function scan_usage {cat << EOTusage: scan [-c] [-h] [-q] [search-reg]Options -c      create output, usable as create arguments -h      help -q      quiet, minimal outputthe optional regular expression is passed to egrepEOTexit;}while getopts hcq o 2>/dev/null; do        case "$o" in                h) scan_usage;;                c) create=true;;                q) quiet=true;;        esac        shift;doneoldifs="$IFS";IFS="";if [[ ! -z $1 && $1 == "help" ]]; then        scan_usage;fiif [[ $create == false && $quiet == false ]]; then        echo -n "scanning $_NETWORK";        if [[ ! -z $1 && $1 != "help" ]]; then                echo -n ", for $1";        fi        echo " ... please wait.";fifor 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";        fidoneIFS="$oldifs";exit 0;