Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Unnamed
Thursday, April 5th, 2007 at 8:31:13am UTC 

  1. #!/bin/bash
  2.  
  3. ip=""; host=""; mac=""; create=false; quiet=false;
  4.  
  5. function scan_usage {
  6. cat << EOT
  7. usage: scan [-c] [-h] [-q] [search-reg]
  8.  
  9. Options
  10.  -c      create output, usable as create arguments
  11.  -h      help
  12.  -q      quiet, minimal output
  13.  
  14. the optional regular expression is passed to egrep
  15. EOT
  16. exit;
  17. }
  18.  
  19. while getopts hcq o 2>/dev/null; do
  20.         case "$o" in
  21.                 h) scan_usage;;
  22.                 c) create=true;;
  23.                 q) quiet=true;;
  24.         esac
  25.         shift;
  26. done
  27.  
  28. oldifs="$IFS";
  29. IFS="
  30. ";
  31.  
  32. if [[ ! -z $1 && $1 == "help" ]]; then
  33.         scan_usage;
  34. fi
  35.  
  36. if [[ $create == false && $quiet == false ]]; then
  37.         echo -n "scanning $_NETWORK";for l in `nmap -sP $_NETWORK | grep ^Host | awk '{print $3"|"$2} ' |\
  38.         sed -e 's/[\(\)]//g'`; do
  39.        
  40.         # use search pattern if there is one
  41.         if [[ ! -z $1 ]]; then
  42.                 l=`echo $l | egrep $1`;
  43.                 if [[ -z $l ]]; then
  44.                         continue;
  45.                 fi
  46.         fi
  47.  
  48.         ip=`echo "$l" | cut -d'|' -f1`;
  49.         host=`echo "$l" | cut -d'|' -f2`; # | sed -e 's/'"asdfasdfasdf"'//';
  50.         host=`echo "$host" | sed -e 's/\.'$_DOMAIN'//'`;
  51.        
  52.         if [[ "`hostname`" != "$host" ]]; then
  53.                 mac=`arp $ip |grep ether| sed -e 's/.*\([0-9A-F:]\{17\}\).*/\1/'`;
  54.         else
  55.                 mac=`ifconfig | grep $_INTERFACE | sed -e 's/.*\([0-9A-F:]\{17\}\).*/\1/'`;
  56.         fi
  57.        
  58.         if [[ $create == false ]]; then
  59.                 echo -e "$ip\t$mac\t$host";
  60.         else
  61.                 echo -e "$host $ip $mac";
  62.         fi
  63. done
  64. IFS="$oldifs";
  65.  
  66. exit 0;
  67.  
  68.         if [[ ! -z $1 && $1 != "help" ]]; then
  69.                 echo -n ", for $1";
  70.         fi
  71.         echo " ... please wait.";
  72. fi

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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

comments powered by Disqus
worth-right
worth-right