Guest User

ono

a guest
Sep 17th, 2009
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.00 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #------------------------------------------
  4. #  scan smb shares in windows network
  5. #  requires: nmap, smbclient, nmblookup
  6. #------------------------------------------
  7.  
  8. # show $ shares
  9. showadm=0
  10.  
  11. fname="$HOME/shares.txt"
  12. iprange="192.168.15,27,19.1-224"
  13. ips=''
  14. t=''
  15. count=0
  16. scount=0
  17.  
  18. /usr/bin/notify-send -u normal -t 2000 -i gnome-network-preferences -c network "SMB shares scanning" "Ping..."
  19. echo "writing shares to: $fname"
  20. echo "Scanned at `date`" > $fname
  21. echo "For exploring some machine:" >> $fname
  22. echo "    smb://ip-address (e.g.: smb://192.168.27.1/)" >> $fname
  23. echo "" >> $fname
  24. ips=`nmap -n -p 139 "$iprange" -oG - 2>/dev/null | grep open | awk '{ printf "%s ", $2 }'`
  25. for i in ${ips[@]}
  26.   do
  27.     t=`/usr/bin/nmblookup -A $i 2>/dev/null | grep "<00> -  " | awk '{ printf "%s", $1 }'`
  28.     /usr/bin/notify-send -u normal -t 800 -i gnome-network-preferences -c network "SMB shares scanning" "Scanning $t ($i)"
  29.     u=`smbclient -N -L //$t/ -I $i 2>/dev/null | grep '^[^Domain]' | awk -v SHOWADM=$showadm '
  30.    BEGIN { isprint=0; preprint=0 }
  31.    {
  32.      if ($1 == "Server" || $1 == "Error") isprint=0;
  33.      curprint=1;
  34.      if (SHOWADM == 0 && $1 ~ /[\$]$/) curprint=0;
  35.      if (isprint == 1 && curprint == 1) {
  36.        if ( $(NF-1) == "Disk" || $(NF) == "Disk") {
  37.          de=0;
  38.          if ( $(NF-1) == "Disk") de=1;
  39.          for (i=1; i < NF-de; i++) { printf " %s", $(i) }
  40.          printf ";";
  41.        }
  42.      }
  43.      if ($1 == "Sharename") preprint=1;
  44.      if ($1 == "---------" && preprint == 1) { isprint=1; preprint=0 }
  45.    }
  46.    END { printf "\n" }'`
  47.     if [ x"$u" != x ]
  48.       then
  49.         count=$(echo "$count+1" | bc)
  50.         echo $i $t >> $fname
  51.         echo "    $u" >> $fname
  52.         echo "" >> $fname
  53.     fi
  54.     scount=$(echo "$scount+1" | bc)
  55.   done
  56.  
  57. /usr/bin/notify-send -u normal -t 5000 -i gnome-network-preferences -c network "SMB shares scanning" "$scount hosts scanned.         $count contain some shares"
  58.  
  59. /usr/bin/gedit $fname &
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment